Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 10 down vote accepted

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"' {} \;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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