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
find
to limit itself to content newer than that file.To keep the prior semantics, where we were running two separate passes, completing all invocations of
jpegoptim
in one mode before going on to the other:As an alternative, consider:
In this latter approach, we're doing only one
find
pass, and then passing each batch of files to a shell, which is responsible for runningjpegoptim
in each mode in turn for that batch.Finally: if
jpegoptim
is safe for concurrent usage, you could do the following:Here, we have a single
find
pass directly starting both copies ofjpegoptim
; the risk here is that ifjpegoptim --strip-all
andjpegoptim --all-progressive
can't safely operate on the same file at the same time, this may behave badly.