This is a follow-up question to this one.
So far, I've cobbled together the following find command, which is intended to print (and once properly tested, -delete) all JPGs that are 200 x 200px or lower:
find . -iname "*.jpg" -type f -exec bash -c 'for i; do size=($(identify -format "%wx%h" "$i")); (( size[1] < 200 && size[2] < 200 )); done;' \; -print
However, piping the command through wc -l indicates that it's selecting every image in the target set.
Breaking it down to the for loop itself shows that it's looping through images much larger than 200px:
for i in *.jpg; do size=($(identify -format "%wx%h" "$i")); (( size[1] < 200 || size[2] < 200 )); echo $size; done;
210x163
1920x1200
1920x1200
240x240
246x138
215x215
1920x1200
1920x1200
240x240
240x240
1920x1200
To me this seems to indicate identify is probably the culprit here in failing to match only those images that are lower than the specified dimensions, but as far as I've been able to tell, the syntax for the matching is correct.
Anyone have an idea what could be causing this?
\;instead of+so it enables me to be able to use-printand then-deletewhen I need to delete the images. – Hashim Aziz Jan 02 '20 at 00:53nothing is being printed– Are you sure there are files that qualify? – Kamil Maciorowski Jan 02 '20 at 01:01size[0] < 200 || size[1] < 200work? b) What exactly isarbitrary-namedoing here? I'm having trouble understanding which command requires it as a parameter. – Hashim Aziz Jan 02 '20 at 19:29&&to||then yes; butsize[0] < 200is not "250px or less". (b) Seeman 1 bashwhere it describes-c.arbitrary-namebecomes$0"used in warning and error messages". The POSIX shell (sh) also works this way. Therefore names likefind-bash-1,find-sh-2orspecial-shellmay be useful: when you get an error with such name, you immediately can tell which "inner" shell generated it. – Kamil Maciorowski Jan 02 '20 at 19:37bash -c? – Hashim Aziz Jan 02 '20 at 19:51findto pass expanded{}to a shell invoked with-execthen you should pass it as a separate argument and refer to it as$1or so in the shell command. Technically you can omit arbitrary name, letfindpass expanded{}right away and refer to it as$0in the shell command. But then in case of any error or warning the expanded{}will be used as the name of the shell, it can be very misleading. For this reason it's good to use any fixed name and then{}(which will become$1). – Kamil Maciorowski Jan 02 '20 at 19:52{}becomes$1, I mean the-exec sh 'shell-code' foo {} \;case. If we use-exec sh 'shell-code' foo {} +thenfindwill expand{}to possibly multiple arguments. They will become$1,$2, … of the inner shell. – Kamil Maciorowski Jan 02 '20 at 19:57bashso many times. If there is just one file to test with-exec, then the former snippet may be little (negligibly?) faster. Why won't you test them? – Kamil Maciorowski Jan 14 '20 at 00:40arbitrary-name: I created a separate question and answered it decently. – Kamil Maciorowski Feb 17 '20 at 22:56