3

I want to find screenshot files, having a specific pixel height of 2220 and width of 1080, and want to move them into another folder. That's nothing I can do manually, as the source is 100+k images or so.

I've found the following command, but not able to bring it to work:

find /Users/myuser/Desktop/daten/JPG -name "*.jpg" -exec bash -c "sips -g pixelHeight -g pixelWidth {} | grep -E '2220‘ >/dev/null" \; -exec mv {} /Users/myuser/Desktop/screenshots \; 

Error message:

bash: -c: line 0: unexpected EOF while looking for matching `'' bash: -c: line 1: syntax error: unexpected end of file 

Thank you for your help.

UPDATE: fixed the command and removed the blank in the folder name to:

find /Users/myuser/Desktop/daten/JPG8 -name "*.jpg" -exec bash -c "sips -g pixelHeight -g pixelWidth {} | grep '2220' >/dev/null" \; -exec mv {} /Users/myuser/Desktop/screenshots \; 

.. but still not working well - no files have been moved.

3
  • sips runs in its own shell, when this shell is terminated its output {} is lost. Either use a tmpfile, export a variable or try to redefine your command. Commented Sep 16, 2021 at 8:14
  • You see that there are 2 different types of quotes: grep -E '2220‘ Commented Sep 16, 2021 at 8:21
  • Could you help please, @paladin, to make it work? Commented Sep 16, 2021 at 8:29

3 Answers 3

2

An alternate to using grep (which adds to the processing time) would be to do a comparison within the bash command, such as:

time find "./JPG*" \( -iname '*.jpg' -o -iname '*.jpeg' \) -exec bash -c '[[ $(exiftool -p "\$ImageSize" "{}" 2>/dev/null) == "1080x2220" ]]' \; -fprintf process_jpeg_files.sh 'mv -ivt "./screenshots/" "%p"\n' 

A few notes:

  1. time is obviously unnecessary, but I'm always interested in getting stats from huge operations.
  2. It's good practice to quote paths, files, etc. in order to handle spaces and special characters. In a similar vein, it's safer to use the parenthesized expression above instead of '*.jp*g' to match both spellings of the file extension (this may seem paranoid, but experience has shown that when dealing with large numbers of files such as you are, the "impossible" has an irritating way of rearing its ugly head).
  3. It's a good practice to actually generate a script to perform bulk processing rather than just take the actions, so that you can review what will happen rather than suffer deep regret. Plus, now you've got a record for posterity!
  4. -p "\$ImageSize" will give you ONLY that property value without the tag names that -csv produces, allowing you to do a simple string comparison instead of having to fire up grep to parse it. As a side note, grepping only for 2220 will give you images with either a width or a height of that amount, rather than what you said: a specific pixel height of 2220 and width of 1080 (note further that you gave the dimensions in reverse order so the above string "1080x2220" gives exactly what you specified).
1

Just to close this question: I have managed to move and finally remove all screenshots with the following command:

find ./JPG* -name "*.jpg" -exec bash -c "sudo exiftool -csv -s -ImageSize {} | grep > /dev/null 'x2220'" \; -exec mv {} ./screenshots/ \; 
1

There's no need to create 5 processes for every single file, i.e. bash, sudo, exiftool, grep and mv. You can just run a single invocation of exiftool to parse all your files and change their "directory" property when a condition is met:

mkdir Screenshots exiftool -ext jpg -if '$ImageWidth==2220 and $ImageHeight==1080' '-directory=Screenshots' . 
1
  • 1
    Brilliant! See what happens when you actually read the manual? ;-) Commented Mar 8 at 17:19

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.