What folders are indexed / covered by 'locate'

On OS X, I think the locate DB is populated by running:

sudo /usr/libexec/locate.updatedb

But locate does not seem to find anything in or below ~/

Should locate.updatedb be indexing my home folder by default? If so, any suggestions or ideas why it is not? If it doesn't index ~/ by default, are there any reasons to not index this folder hierarchy? If not, how do I configure it to do so?


Also, when I run locate.updatedb from ~/ (as non-root) it works. When I run it from anything below (for example, ~/Desktop/) I get the following errors:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
find: .: Permission denied

Solution 1:

Locate runs as the "nobody" user to prevent other users from being able to see "your" files in the locate database. As your account is the only one with permission to explore your files, locate can't see them. Even if your account is the sole local user, this limitation applies. When you sudo the locate.updatedb script, the find command it spawns is specifically started as unprivileged. While you could modify the script to prevent this issue, I can't say it's recommended.

Also, locate is not enabled by default as it is presumes Spotlight/MDS are better for most people. I'd suggest trying out the mdfind command. If you do decide you want locate to run regularly, execute sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist to load its launchd job for regular re-indexing.

Solution 2:

One can get locate to search almost everywhere by modifying /usr/libexec/locate.updatedb.

Change:

if [ "$(id -u)" = "0" ]; then

to, say,

if [ "$(id -u)" = "1" ]; then

Some reduction in security. Use only on a personal computer.