How to use Jpegoptim recursively

Jpegoptim is a Linux software that does what the name suggests: is does optimize jpg images. It is one of the two recommended software for Google Pagespeed optimization.

As this software doesn't have a recursion parameter, we use a trick to parse all the subdirectories where we have jpeg images to be optimized.

The command uses find:

find -type f -name "*.jpg" -exec jpegoptim --strip-all {} \;

Now be patient and wait until it does the job. You will probably be surprised how much it can reduce the size of some images (up to 40% for some thumbnails!).

Read about how to optimize PNG and GIF files with OptiPNG.

If you know a better aproach into using this cool software, please leave a comment below.

Rate this article: 

Average: 2.6 (37 votes)



Don't forget those files that end with .jpeg! :)

Yeah, very seldom used, but thanks for reminding!

You need to put a directory to search, ie
find . -type f //etc

The . will start in the current directory.

thanks, for the tutorial :)

@walk i just changed it to "*.jp*g" :)



Samples of work done for me or my customers, for free or not, like websites, repairs, photography etc.
View all my recent work



I'm giving away some knowledge in my areas of expertise. Did you like something here? Share it please!
View all tutorials



Useful Linux commands or other code snippets I often use.
View my useful shortcuts



Few bookmarks I find useful. Do you want website here? Give me a good reason and I can help you.
View my favourite web resources

About me

Hi there! My name is Marius Cârneală.

About me?

Loving husband, dad of one two three, drone pilot, web designer and administrator, SEO specialist, IT support guy, electronic hobbyist and content writer. This list is open.