How to convert jpg files into png files with linux command? + Difficulty = Subfolders

Merrythought picture Merrythought · Jan 7, 2014 · Viewed 39.6k times · Source

I want to convert several jpg files into png files. As far as I know, one can use this command

mogrify -format png *.*

I have one problem, I have a lot of subfolders. Let's say a is my main folder and b,c and d are subfolders. The images are in the subfolders.

How can I convert all images without having to open every folder manually?

-> I would like to write a command that works, when I am in folder a, but works for all files in the subfolders.

Answer

arco444 picture arco444 · Jan 7, 2014

Assuming you're in folder a the following might work for you

find . -name "*.jpg" -exec mogrify -format png {} \;

You can use the find command to get all the jpg files in all the subfolders and pass your command as an argument to find