2

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.

3

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:

  • Is it possible on macOS Mojave, or is it protected by system integrity? – Yannick Jan 18 at 18:40
1

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.

  • 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. – Lri 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. – pasawaya Sep 7 '12 at 11:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .