I need to create thumbnails from multiple .png files and would like to do this using ImageMagicks convert utility. To recursively find all files that are not thumbnails themselves, I am using the following call (split into two lines to make it readable):

find . -type f -name "*.png" -not -name "*thumb.png*" \
  -exec convert {} -thumbnail 200x200 {}.thumb.png \;`

But this would of course create a file named a.png.thumb.png when running it on a file called a.png. How could I remove the .png extension from the second {} parameter passed to convert?

1 Answer 1


The easiest way to do this is to pass the {} off to a shell like sh and have the shell do it:

find ... \
    -exec sh -c 'convert "$0" -thumbnail 200x200 "${0%.png}.thumb.png"' {} \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.