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.

1
  • 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? Commented Aug 16, 2016 at 3:02

2 Answers 2

0
find thumbs/ -not -name "*-s.jpg" -exec mogrify -resize 50% -quality 85 -strip {} \;
2
  • 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. Commented Aug 16, 2016 at 4:08
  • 1
    Replace -not with ! to make it standard/portable. Commented Aug 16, 2016 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 {} \;

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.