1

The com.apple.locate.plist daemon is running, and I've updated the database using sudo /usr/libexec/locate.update, but the locate command is still not finding a .zip named OldPhoneCamera.zip in /Users/CAJ/Pictures/.

I use this command locate -i OldPhoneCamera, and it returns nothing. The directory is not hidden, and the file has been on the system for 6 months. The database has been updated multiple times since then.

I can use find successfully, find / -name OldPhone*, but I prefer using locate because find takes a long time. Why is locate not finding OldPhoneCamera.zip, and can that be fixed?

1

The shell script /usr/libexec/locate.updatedb is run by the non-privileged user nobody. Here's the snip it:

if [ "$(id -u)" = "0" ]; then
rc=0
export FCODES=`sudo -u nobody mktemp -t updatedb`
chown nobody $FCODES
tmpdb=`su -fm nobody -c "$0"` || rc=1
if [ $rc = 0 ]; then
    install -m 0444 -o nobody -g wheel $FCODES /var/db/locate.database
fi
rm $FCODES
exit $rc
fi

The script will barely touch anything within your home folder.

  • I see, thanks. I guess I can add permissions for 'nobody' to a bunch of places. I wonder why it was done this way, the linux version works well for all directories. – CAJ Jul 31 '18 at 19:27
  • @CAJ Since the locate database can be read by every user, it is considered a security risk exposing the files within each user's home folder in the database. It would not be that difficult to create a user locate database to use with the "system" locate database but that would be off topic here. – fd0 Aug 1 '18 at 13:37
0

The database used by locate is updated only once a week, which is hardly ideal in terms of receiving accurate results.

Most importantly, as it says in the man page, locate's behavior is intentional; the intent is to minimize the number of entities with read access to your personal files:

The locate database is typically built by user "nobody" and the locate.updatedb(8) utility skips directories which are not readable for user "nobody", group "nobody", or world. For example, if your HOME directory is not world-readable, none of your files are in the database.

When performing a casual command-line search on a Mac, the usual procedure is to use locate for system-owned files and the GUI process "Spotlight.app" for your files. (Spotlight is perfectlY capable of performing complex searches as well, and it's fast.) It's easily launched from the Finder by holding down the command key and tapping the spacebar.

  • While spotlight is great, I often need something that can search through all the files on the system in the terminal. For example, earlier today I needed to locate a file to scp it from an OSX machine to a linux machine. I knew the file name, but not where it was. This and similar scenarios come up frequently. I use locate frequently in linux, so I am a bit disappointed that it doesn't work as well for me here. – CAJ Aug 1 '18 at 5:14

You must log in to answer this question.

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