How do I add a directory to be indexed by locate.updatedb on macOS / BSD so that I can find files in that directory with the locate command?

I read the man page of locate(1) on Mac, but didn't find anything useful.

1 Answer 1


The locate(1) man page tells you how to use the locate command to look stuff up. As the indexing is done by locate.updatedb, you should read the locate.updatedb(8) man page instead.

But on a macOS Big Sur at least, the information relevant to your question is rather limited. Basically it just says:

The contents of the newly built database can be controlled by the /etc/locate.rc file.

By default, all the settings in /etc/locate.rc seem to be commented out. The relevant lines for your question are:

# directories to be put in the database

# directories unwanted in output
#PRUNEPATHS="/tmp /var/tmp"

# filesystems allowed. Beware: a non-listed filesystem will be pruned
# and if the SEARCHPATHS starts in such a filesystem locate will build
# an empty database.
# be careful if you add 'nfs'
#FILESYSTEMS="hfs ufs apfs"

Assuming the file follows the convention of presenting the default settings as commented-out examples, it seems that everything located on HFS, UFS or APFS filesystems will be indexed by default, except the contents of /tmp and /var/tmp.

If the directory you wish to add is located on one of those filesystem types, and is not under /tmp or /var/tmp, the directory should automatically get indexed the next time locate.updatedb runs.

Note that many variants of locate will check for access permissions when displaying the results, and will only show you files you would have permission to see.

  • I did some tests, and it seems that not all files on the (APFS) filesystem on macOS Big Sur 11.5.2 (Intel) are indexed - locate can find /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/google-chrome.rb, but not /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask-versions/Casks/google-chrome-canary.rb, and it can't seem to find contents in ~/my-custom-dir.
    – Teddy C
    Aug 28, 2021 at 4:07
  • According to the locate.updatedb(8) man page, the database is updated only once a week by default - did you run the update task manually for testing?
    – telcoM
    Aug 28, 2021 at 4:11
  • No, I didn't run locate.updatedb before the tests. But these brew tap dirs and ~/my-custom-dir has been on my mac for months, so they should be indexed, right?
    – Teddy C
    Aug 28, 2021 at 4:12
  • Hmm. Also, on macOS you can use the mdfind command that utilizes the Spotlight search engine and its databases, which might be a better option than relying on the very basic locate.
    – telcoM
    Aug 28, 2021 at 4:15
  • 1
    Since Spotlight is the primary search engine on macOS and locate is just something that was inherited from macOS's BSD origins and probably hasn't received much attention, I think that's a good assumption to make.
    – telcoM
    Aug 28, 2021 at 4:37

You must log in to answer this question.

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