Searching in osx for "anything but.."

1

I was trying to clean up my music folders and I want to remove everything except MP3 files.

I want to know how to search for everything but MP3s and obviously the subfolders themselves.

What do I have to type into the searchlight box to achieve that?

stoobz

Posted 2014-06-17T18:11:32.303

Reputation: 21

Answers

2

Enter anything into the Finder's search field, and clear it again. You'll then be in the search interface that has a new bar near the top, with no active search criteria:

Screenshot

Click the + button at the right side of the new search context bar.

Hold Option and click the button to the right of the new entry (it's another + button while you don't hold Option).

Now it should look like this:

Screenshot

Remove the first additional row (the one that showed the button) by clicking its button.

Then, configure the two recently added rows to say:

  • None of the following are true
    • Kind is Music MP3

Here, I'll still need to change All to MP3, but otherwise, I'm done:

Screenshot

Daniel Beck

Posted 2014-06-17T18:11:32.303

Reputation: 98 421

Thanks Daniel, I didnt know the trick with the option-click ;) But it also shows me the folders - any way to exclude them as well? or another possibility would be to have a bar on top to sort the results by type or date or name, etc... – stoobz – 2014-06-17T21:05:40.013

@stoobz: Just add another line to the None block that excludes the Kind Folder – Daniel Beck – 2014-06-17T21:15:26.303

1

Assuming you want to delete non-mp3 files anywhere under a specific directory (which I assume is the current directory), and that they are all called names ending in .mp3, the following should work.

find . -type f \! -name \*.mp3 -exec rm {} \;

A simpler way, pointed out in a comment below (thanks, @DanielBeck!), would be to use the -delete option instead.

find . -type f \! -name \*.mp3 -delete

This finds all ordinary files (-type f) whose name does not (\!) match the pattern *.mp3, then deletes them (-exec rm {} \;, or the rather simpler -delete option).

holdenweb

Posted 2014-06-17T18:11:32.303

Reputation: 160

thank you! I will try that. and to define the folder I have to replace the first "." with the folderpath, right? – stoobz – 2014-06-17T18:42:39.910

-delete is a better alternative to -exec rm. – Daniel Beck – 2014-06-17T18:47:05.433

@stoobz - yes, the first arguments to find are the path to search (and you can give any number of directories). – holdenweb – 2014-06-17T18:56:22.987

@Daniel - thanks, shows my knowledge isn't as current as yours, probably. How often we learn one way to do a task then stick with that, even in the presence of better ways. – holdenweb – 2014-06-17T18:56:47.563