How to search files with specific pattern on os x

1

1

I'm looking for a way to search a huge folder of images, and select only the file names that ends with a pattern like: 800x600.jpg or 645x321.jpg etc'

There must be some raw search command for the finder search for that. Regex-based...

Thanks Dan

Tech500

Posted 2016-09-11T07:50:04.910

Reputation: 11

Is grep not available in osx?! – adampski – 2016-09-11T08:18:58.627

It is, but I have no idea how to use all these grep/regex commands... – Tech500 – 2016-09-11T09:33:06.923

Answers

1

This is an example that I just tested - this should give you a filtered list of all files that have the pattern of 3 digits followed by an x followed by 3 digits and then the extension of jpg.

ls | egrep "\d{3}x\d{3}\.jpg"

Similarly in general you can list all files in a directory (in the Terminal.app of course) using the ls command, and then use the pipe (|) to pass the list of files to grep or egrep. I like using egrep because it has a nicer syntax for regular expressions. You can also achieve the same effect by using grep -E. Both are already available on OS X. Good luck!

Ambidextrous

Posted 2016-09-11T07:50:04.910

Reputation: 181

I have tested and it works on a folder, but doesn't scan all sub folders. Also, since it's terminal command, how can I select and delete the found results ? Thansk – Tech500 – 2016-09-12T08:16:09.590

Most UNIX commands have an optional recursive flag which will help you scan all the sub folders. – Ambidextrous – 2016-09-23T23:21:17.293

1

To add to Ambidextrous's answer, with the extra bits you've asked for in the comments:

ls | egrep -r "\d{3}x\d{3}\.jpg" | xargs rm

Warning This will delete everything it matches, I would recommend you copy the entire folder you want this to work on, then run the above command in that directory to look at the results.

If you want to delete all without a prompt for each file, add the -f flag after xargs rm

adampski

Posted 2016-09-11T07:50:04.910

Reputation: 1 164

0

I don't know if this is a "super user" enough answer, but I use a free program called easyFind. Which can be found here : www.devontechnologies.com/products/freeware.html

Spyderspyders

Posted 2016-09-11T07:50:04.910

Reputation: 1