Your images take too much space on Your web server? You just realized that Your server disk usage is near 100%? You can buy Yourself some time with some simple image optimization from Your command line, all at once.
For this example jpegoptim will be used (it’s already included in most Linux distros and it does the job).
We need to find the files with JPG/JPEG extension, and execute jpegoptim on the files:
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --strip-all {} \;
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --size=250k --strip-all {} \;
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --size=200k --strip-all {} \;
find . -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) -exec jpegoptim -f --size=150k --strip-all {} \;
Depending on the number of images on Your server, this simple task can save a lot of space, mesurable in GB’s.
It can also be added to cron tasks to repeat this optimization once in while. To achieve that, create a file somewhere on Your server, for example jpegoptim.sh, add shebang (#!/usr/bin/env bash) on the first line of the file so the system can understand how to process the commands, add execution permission (chmod +X /path/to/file/jpegoptim.sh) and add it to cron list using crontab -e, for example: * * * * * sh /path/to/file/jpegoptim.sh > /dev/null