By default, the process to rebuild the locate database runs as user nobody
. This prevents it from indexing the content of user directories (which would be a security risk on systems with more than one human user).
Rebuilding the index with sudo
doesn't help. At the top of /usr/libexec/locate.updatedb
, there is
if [ "$(id -u)" = "0" ]; then
#ifdef __APPLE__
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
#else
# echo ">>> WARNING" 1>&2
# echo ">>> Executing updatedb as root. This WILL reveal all filenames" 1>&2
# echo ">>> on your machine to all login users, which is a security risk." 1>&2
#endif
fi
This checks whether the command is run as root
and, if yes, reruns it as user nobody
(the tmpdb=...
part).
So, if you want to index your home directory, you need to create a copy of /usr/libexec/locate.updatedb
and remove the whole section. Also, you need to disable the default launch daemon and set up your own in /Library/LaunchDaemons
.
sudo
forlocate
. If a file is not in the index, it's becauselocate.updatedb
didn't add it. You could try to dochmod 755 ~
first, and runsudo /usr/libexec/locate.updatedb
afterwards, but even that will not index files in~/Documents
etc (unless you chmod those directories as well).