1

I'm trying to run the convert command on some images to resize them.

find build_reports/functional_tests/results -name '*.png' | xargs -I {} sh -c 'convert -resize 20% {} {}'

The problem that I have is that the files have ( and ) in their names (e.g. build_reports/functional_tests/results/Attachments/Screenshot of main screen (ID 1)_1_0FEF8183-AF87-4517-928D-8C4A2ED984D0.png) and I cannot rename these files because their linked somewhere else.

When I run the command I get the following warnings and the images are not resized

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `convert -resize 20% build_reports/functional_tests/results/Attachments/Screenshot of main screen (ID 1)_1_D94BAEBC-F463-4EEE-8FAE-C49AFF4A8FFE.png {}'

Is there anyway to get rid of these warning and make this work by somehow escaping the result of the find command?

Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121
  • 1
    Use -print0 in find and -0 in xargs, and put the file names between quotes: find /path -print0 -name *.png | xargs -I {} -0 convert... '{}' '{}' – Ramon Poca Nov 28 '17 at 10:00
  • See https://stackoverflow.com/questions/16758525/how-can-i-make-xargs-handle-filenames-that-contain-spaces – Ramon Poca Nov 28 '17 at 10:03

1 Answers1

1

Give a try to this:

find . -iname "*.png" -exec convert -resize 20% '{}' '{}' \;

Notice the single quotes'{}'

nbari
  • 25,603
  • 10
  • 76
  • 131