find - Packet jpeg optimization in linux -
i have many jpeg images on server , added evry day. need optimize images.
to optimize have use next command
find . -iname "*.jpg" -exec jpegoptim -m85 --strip-all {} \;
but find command finds images, not new! know, may specify -ctime , -mtime params, when jpegoptim optimizes image, image creation time changes now! therefore can not specify last mod time find command.
i think, solution save processed files names in text file , when find command runs again exclude processed file.
how can this? how add finded file name in text file, , how check file name in text file in next path?
you use inotifywait
inotify-tools (or other inotify
frontend) continuously monitor folder contains jpegs , have them converted on fly, uploaded.
$ inotifywait -mrq --format '%w%f' -e create . | while read file; [ "${file##*.}" = "jpg" ] || continue; [ -f "${file}" ] || continue; echo "jpegoptim -m85 --strip-all '$file'"; done
this watches file creations in current folder (-e create .
) recursively (-r
) , have check file extension (.jpg
) shown, means in case there lots of non-jpeg creations in same folder unnecessary overhead. if problem you, use --exclude
argument , specify negated regex filter out files not match desired extension (which cumbersome , not nice , straight-forward) or can checkout current version git repo provides --include
filter (v3.14
not have it) , have inotifywait
report files matching criteria.
also note silently skip files newlines in filenames.
Comments
Post a Comment