Saturday, 4 January 2020

macos - 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

Answer



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.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...