1

I have folders and files looks likes this:

/thumbs/6b0/6b029aab9ca00329cd28fd792ecf90a.jpg
/thumbs/6b0/6b029aab9ca00329cd28fd792ecf90a-s.jpg
/thumbs/d11/d11e15a72e20e14c45bd2769d763126d.jpg
/thumbs/d11/d11e15a72e20e14c45bd2769d763126d-s.jpg

And I want to apply following command to the files not have -s in their names in all sub directories in thumbs folder.

mogrify -resize 50% -quality 85 -strip filename.jpg

I have look around find and grep but couldn't figure out how can I do this.

Any help appreciated.

  • 2
    I'm confused which files you want to match exactly - in one case you appear to have 32 hex digits plus the .jpg suffix, and in another 33 hex digits plus the suffix (each with and without the -s). Should both the non -s files match, or only the 32 digit one? – steeldriver Aug 16 '16 at 3:02
0
find thumbs/ -not -name "*-s.jpg" -exec mogrify -resize 50% -quality 85 -strip {} \;
  • Thank you very much for your reply but it gives me following errors: root@test /home/test/assets/thumbs/test # find . -not -name "*-s.jpg" -exec mogrify -resize 50% -quality 85 -strip {} \; mogrify: no decode delegate for this image format .' @ error/constitute.c/ReadImage/532. mogrify: no decode delegate for this image format ./f1' @ error/constitute.c/ReadImage/532. mogrify: no decode delegate for this image format `./f2' @ error/constitute.c/ReadImage/532. – user260223 Aug 16 '16 at 4:08
  • Sorry, It is working though, thank you! – user260223 Aug 16 '16 at 4:19
  • 1
    Replace -not with ! to make it standard/portable. – Stéphane Chazelas Aug 16 '16 at 6:44
0

To answer the question in the subject:

find . -name '????????????????????????????????.jpg' -exec cmd {} \;

To insert those 32 ?s, with tcsh, zsh or bash in emacs mode, type Alt+3Alt+2?. With those shells and ksh in vi mode, enter a ?, leave the insert mode with Esc, then press x to cut that ?, and then 32p to paste it 32 times.

With GNU find, you can also do:

find . -regextype egrep -regex '.*/[^/]{32}\.jpg' -exec cmd {} \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.