Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 5 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 "$1" -thumbnail 200x200 "${1%.png}.thumb.png"' convert {} \;
share|improve this answer
add comment

Your Answer

 
discard

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.