Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question
    
Do you use FileVault? –  Daniel Beck Jan 24 '11 at 7:42
    
Nope I do not use FileVault. –  user31752 Jan 24 '11 at 7:49

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer
    
That last part is right from the uninitialized locate help message, so it's recommended by Apple. –  Daniel Beck Jan 24 '11 at 8:24

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.