I am trying to find all JPG images within a folder with subfolders that have either width or height below 300px.
This way I want to detect old thumbnails and delete them.
For sure I can find all images using find
:
find . -iname "*.jpg" -type f | ...
But what follows after the pipe? Which package can I use to detect picture attributes?
Best Answer
You can use
identify
fromimagemagick
, and you can use the following command:the use of
-exec <command> '{}' \;
makes sure that your filename can have spaces in them, alternatively you can usewhere the
-I{}
takes care of the same thing.What I like about
identify
is that you can specify the output format; in this case'%w %h %i'
which gives the width, height and full pathname of the image. Then theawk
expression only keeps those lines for which the image is smaller than the desired size.Example of the output:
Edit: If you want the filenames only (for piping to
rm
for instance), simply change$line
in theawk
statement to$3
, then it will only print the third column.