MacOS – How to Spotlight index a folder under /private/var

macosmdsspotlight

I got a directory /private/var/directory that I'd like to index using Spotlight. It looks like everything under /private/var/ is excluded from indexing. I tried to import it using:

mdimport /private/var/directory

But it didn't work. I also thought it might be excluded by some kind of sandboxed environment, but I couldn't figure out if that is the case.

As a last resort I could move the directory somewhere else but I'd rather not do that as it would be a lot of work in this particular case.

How can I force Spotlight to index this directory?

Best Answer

As you know it is a Hidden Folder and therefore it is not indexed by Spotlight.

You could change the Flag for the folder from hidden to no hidden using the terminal command:

sudo chflags nohidden /private/var/directory

To test, using Finder navigate to the /private/var/directory with Go To.

Now right click and use Get Info. does it still show it as Hidden?

get info

To make Spotlight re-index that folder:

From the Apple () menu, choose System Preferences.
Click Spotlight.
Click the Privacy tab.
Drag a folder or an entire volume (your hard drive) to the list.
If prompted for confirmation, click OK.
Remove the item or volume you just added to the list by clicking it and then clicking the minus ("-") button.
Close Spotlight preferences.

Spotlight will re-index the contents of the folder or volume.