4

This question already has an answer here:

I have restored with photorec about 7.500 jpg's. I have moved them all in one folder. A big portion of them is thumbnails. But i can't just go on and delete lets say all of them that are smaller than X bytes because i have some old pictures which were taken from older phones. So there are thumbs that are 15KBs and also regular photos of about the same size but with bigger resolution (dimensions).

So i want a way to remove those that are smaller than x pixels wide for example. Can this be done from the terminal?

Thanks.

marked as duplicate by Stéphane Chazelas, slm, Anthon, terdon, phunehehe Oct 21 '13 at 15:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • If the big (in size) photos are the majority, it is probably safer if you move then to another folder and manually (previewing each image) chose which one you want to delete... Always be careful deleting photos, you might not have another chance save that moment. – RSFalcon7 Oct 21 '13 at 13:50
1

The imagemagick command identify allows you to find the size from a command line:

1015 % identify YearbookPhoto.jpg 
YearbookPhoto.jpg JPEG 349x395 349x395+0+0 8-bit sRGB 13.5KB 0.000u 0:00.000b

I hesitate to give an example, as this task seems like it needs human guidance, but I would automate each step. For instance, to get a list of images with size:

find . -type f -exec identify \{\} \; | awk '{print $1, $3}' > ../somefile

You're going to need a program to parse the "NxM" dimensions, and decide which file names to delete. Maybe instead of deleting, move the files to a temporary directory, so you can inspect the results and recover anything that got moved mistakenly.

  • 2
    A little bit improvement to your command: find . -type f -exec identify \{\} \; | awk '{split($3,a,"x"); if (a[1] < 151 && a[2] < 151) print $1}' | xargs rm will remove files smaller then 150x150 – Krzysztof Szewczyk Oct 10 '18 at 19:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.