Skip to content

Instantly share code, notes, and snippets.

@jahed
Last active May 6, 2020 19:03
Show Gist options
  • Save jahed/73687eb0426b49d61576eeadb8b88c74 to your computer and use it in GitHub Desktop.
Save jahed/73687eb0426b49d61576eeadb8b88c74 to your computer and use it in GitHub Desktop.
Batch image optimisation.

Add -mtime -2 to limit files by last modified time. -2 to means "in the last 2*24 hours from now".

find . -type f -regex '.+\.jpg' -print0 | xargs -0 -L 1 -I % jpegtran -optimize -copy none -progressive -outfile '%' '%'
find . -type f -regex '.+\.png' -print0 | xargs -0 -L 1 -I % optipng -quiet -out '%' '%'
find . -type f -regex '.+\.png' -print0 | xargs -0 -L 1 -I % pngquant --speed 1 --ext '.png' --force '%'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment