Exclude files from "central metadata store"
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
:
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.