Locate is not finding a zip file that exists

filesystemterminal

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?

Best Answer

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.