This question already has an answer here:

I know convert changes from a image format to another. mogrify can resize and scale multiple images also. But HOW can i modify all images inside a directory, including the sub-directories. Like for example change every image inside a folder and its sub-folders from one format png to another format jpg.

Or resize all pictures in a folder and its sub-folders to a desire one.

marked as duplicate by Evan Carroll, Ravexina, user364819, Charles Green, Anwar May 17 '17 at 6:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Since mogrify accepts a list of files, separated by line breaks, you can do this:

mogrify -equalize $(find -iname '*.png')

I use equalize as an example, but the important bit is the last one.

  • The file name can be any expression that prints out a list of files, i use find -iname '*.png' as an example. You can play around with the find command until it give you the list of files you want.

It's important that whatever command you put in $() returns a list of files with their correct path. ls -Ra will just return the file name. The output of find | grep png on the other hand looks like this:


Where . means "the current working directory".

  • 1
    Why won't you use find -exec? – Elazar Leibovich Jan 1 '11 at 22:34
  • @Elazar never mind me :-) I've changed the answer completely now, there's a much easier way. – Stefano Palazzo Jan 1 '11 at 22:37
  • s/$(find|grep png)/$(find -iname '*.png')/ and you're OK. – Elazar Leibovich Jan 1 '11 at 22:45
  • 1
    Nice. i knew how to use find but never occured to me. Thank god for Linux. – Luis Alvarado Jan 1 '11 at 22:54
  • Done that, thank you very much @Elazar. As I said, it's good to play around with find, you can have much more granular control over what files are modified, for example, excluding all that contain "-thumbnail" or something like that. – Stefano Palazzo Jan 1 '11 at 22:55

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