I have thousands of images which I optimize weekly by running it over a cronjob. My Problem is that it search also optimized images which lower the CPU. How could I save the last scan / optimization and began to optimize Files and Folders after this Date?
My Code
find . -name '*.jpg' | xargs jpegoptim --strip-all
find . -name '*.jpg' | xargs jpegoptim --all-progressive
chmod -R 777 *
The easy thing to do is to touch a file to track the most recent processing time, and to tell
findto limit itself to content newer than that file.To keep the prior semantics, where we were running two separate passes, completing all invocations of
jpegoptimin one mode before going on to the other:As an alternative, consider:
In this latter approach, we're doing only one
findpass, and then passing each batch of files to a shell, which is responsible for runningjpegoptimin each mode in turn for that batch.Finally: if
jpegoptimis safe for concurrent usage, you could do the following:Here, we have a single
findpass directly starting both copies ofjpegoptim; the risk here is that ifjpegoptim --strip-allandjpegoptim --all-progressivecan't safely operate on the same file at the same time, this may behave badly.