Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 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.

share|improve this question
up vote 2 down vote accepted

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".

share|improve this answer
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
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

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.