Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've read through man pngcrush and it seems that there is no way to crush a PNG file and save it over the original. I want to compress several folders worth of PNGs so it would be useful to do it all with one command!

Currently I am doing pngcrush -q -d tmp *.png then manually cut-pasting the files from the tmp directory to the original folder. So I guess using mv might be the best way to go? Any better ideas?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

(All one line:)

for file in *.png ; do pngcrush "$file" "${file%.png}-crushed.png" && mv "${file%.png}-crushed.png" "$file" ; done

should do it.

(THough so far in my own tests, less than half of the pngs I tested pngcrush on were smaller afterwards, so color me unimpressed.)

share|improve this answer
Thanks! The amount you can compress the PNGs can depend on how they were made. I believe Photoshop's "Save for Web" has some form of PNG crusher built in. –  DisgruntledGoat Feb 17 '11 at 10:40
Most of mine were created with ImageMagick's import command. I avoid commercial software like Photoshop whenever possible. –  frabjous Feb 17 '11 at 17:45
use -brute for better compression. –  Collin Anderson Aug 7 '12 at 3:00
add comment

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.