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.

AReddy
  • 3,122
  • 5
  • 35
  • 75
user260223
  • 13
  • 2
  • 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 03:02

2 Answers2

0
find thumbs/ -not -name "*-s.jpg" -exec mogrify -resize 50% -quality 85 -strip {} \;
Stephen Harris
  • 42,369
  • 5
  • 94
  • 123
Ipor Sircer
  • 14,376
  • 1
  • 27
  • 34
  • 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 04:08
  • Sorry, It is working though, thank you! – user260223 Aug 16 '16 at 04:19
  • 1
    Replace `-not` with `!` to make it standard/portable. – Stéphane Chazelas Aug 16 '16 at 06: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 {} \;
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501