Reputation: 5341
I need to list all images in a folder and its sub-folders, with certain size, say all images that are 320x200, I guess I need to do ls -R *.png
then pipe the output to some other command that filters images for that size, my command line skill is pool, can anyone help? Thanks a lot!
Upvotes: 3
Views: 3978
Reputation: 521
In MacOSX there are more helpful terminal commands using metaData (similar to Spotlight):
mdfind, mdls
etc. (manual pages exist and can be shown with man mdls
…). For what you want to do try mdfind
, as shown in the following example to find all files in a given folder (and only in this) with a pixel size greater than 900 x 1100:
mdfind -onlyin /Users/hg/Pictures/2014/01/01 "kMDItemPixelHeight>1100 && kMDItemPixelWidth>900"
The (a bit strange looking) query parameter names can be found in the documentation at DataManagement --> File Management --> MDItemReference. Try mdls filename
to see some of these parameters.
Upvotes: 2
Reputation: 47169
You can use sips to get pixelHeight
and pixelWidth
from images. By combining the command with find you'll be able to recursively search images of a specific size.
example:
results=$HOME/Desktop/results.txt
find . -type f -name "*.png" -exec sips -g pixelHeight -g pixelWidth > $results {} \;
cat $results | grep "\w\{11\}\:\s\(320\)" -B 1 -A 1 | grep "\w\{10\}\:\s\(200\)" -B 1
results.txt:
/Users/Me/Desktop/nsfw.png
pixelHeight: 320
pixelWidth: 200
info:
These commands can be refined however you want and possibly condensed, but should work as is.
Upvotes: 3