Is there a way to globally ignore folders with a certain name (say node_modules)

I know I can do it manually for each instance but I was wondering if its possible to just let spotlight know not to index these folders? node_modules, for example, typically has thousands of files that I don't want to search and it ends up slowing down spotlight.

I've looked around but I can only find answers that suggest manually adding folders in spotlight privacy list. Does someone have a better, glob way to it?

  • 1
    Adding specific folders to the Spotlight privacy is the way to have it ignore during indexing. Why are you against doing it the Apple-provided way? – fsb Jul 24 '16 at 3:29
  • 3
    Because I want to ignore many instances of this folder and doing that "the apple-provided way" will be time-consuming and ineffective (I might miss some). In addition to that, whenever a new node_modules folder is created, I'll have to go and add it manually. – rzr Jul 24 '16 at 3:35
  • See also apple.stackexchange.com/questions/87090/… – mems Jun 6 '17 at 17:20

There is no known method to exclude from Spotlight a file or a folder based on a pattern (ex.: its name).

However it's possible to exclude a folder from Spotlight by adding to it an empty file .metadata_never_index.

You can use this method to ignore all node_moduleand bower_modules folders:

find /path/to/projects -type d \( -name "node_modules" -o -name "bower_modules" \) -exec touch "{}/.metadata_never_index" \;
| improve this answer | |
  • 5
    I cannot confirm that this works for my Mac with Sierra as of today. I ran the script and can find all the hidden .metadata_never_index files in my node_modules, yet after a forced refresh of the spotlight index, the files are still being indexed. There is also a node_modules NPM Github PR open but I am afraid that this won't be the final solution to the problem github.com/npm/npm/issues/15346 – pascalwhoop Jun 5 '17 at 16:59
  • Note: Chrome and Opera use it for profile folder. See bugs.chromium.org/p/chromium/issues/detail?id=395300#c5 – mems Jun 6 '17 at 17:14
  • 2
    Sadly .metadata_never_index is not honored on mojave. – Karl Pokus Sep 4 '19 at 11:51

In case anyone missed fsb's comment in the question, as I did. Apple provides a privacy tab in the Spotlight settings.

Goto "System Preferences" > "Spotlight" > "Privacy" > "+" Add folders to the list.

Note: This may not work immediately, I had to restart Spotlight to see the effects.

| improve this answer | |

Apparently adding '.noindex' to a parent folder name will prevent Spotlight from indexing.

NB: I haven't personally verified.

| improve this answer | |

You must log in to answer this question.

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