Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm fairly familiar with the mdfind utility. I find it's very useful when I can't find a file or when I need to find a file with certain contents. The problem is that I need to exclude some files from mdfind searches. I don't want to exclude the files from a single search (I know you can do this with mdfind -onlyin /path/to/directory/to/exclude) but from all searches. The mdfind man page says this:

The mdfind command consults the central metadata store and returns a list of files that match the given metadata query.

So I guess I have to exclude/delete the files from the "central metadata store" in order to exclude them from mdfind searches. I'm wondering how I would do this.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The command mdfind uses the Spotlight backing store. If you go to the Spotlight pane of System Preferences and select the Privacy tab you can exclude files or folders from being indexed.

It is also possible to modify the exclusions list at the Exclusions array of /.Spotlight-V100/VolumeConfiguration.plist but this does not appear to be officially supported. Current exclusions can be read using the command:

sudo defaults read /.Spotlight-V100/VolumeConfiguration.plist Exclusions

New entries to the Exclusions array can be added using the command:

sudo defaults write /.Spotlight-V100/VolumeConfiguration.plist Exclusions -array-add 'path/to/exclude'

where /path/to/exclude is a path relative to filesystem root.

These entries appear in the System Preferences privacy list but do not appear to actually affect the search results even after running sudo launchctl stop com.apple.metadata.mds && sudo launchctl start com.apple.metadata.mds:

share|improve this answer
    
Thanks! That worked. –  qegal Sep 6 '12 at 20:17

Credit goes to @Lri:

An alternate way to remove files from the Spotlight index is to place them in a folder beginning with a period or add ".noindex" to the end of a folder's name.

share|improve this answer
    
Spotlight does index folders in ~/Library/, but they aren't shown in the Spotlight menu or Finder by default. If you actually want to remove a folder from the index, you could move it to a folder that starts with a period or add .noindex to the end of its name. –  ؘؘؘؘ Sep 7 '12 at 10:31
    
@Lri - Okay. I just thought that ~/Library wasn't index because I was following the article. Anyway, your second piece of information is really useful. Thanks. –  qegal Sep 7 '12 at 11:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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