I can never remember how to update my locate database. locate is a very useful little command, which searches your hard drive for any file or path name that contains the letters you ask for. It works much faster than doing find because it builds a database of filenames and searches that rather than actually running around the disk hierarchy.
But it requires that the database be kept up to date. This is one case where the Linux world has it all over the FreeBSD world. The GNU locate updates itself just by passing it the '-u' flag. But the FreeBSD locate doesn't do this. Rather it has a couple of mysterious command files that are carefully hidden away in the bowels of FreeBSD. The main file, as documented in the man page, is /etc/periodic/weekly/310.locate
. This is one of the periodic commands that is run, but it, for some reason, is only run weekly, which doesn't seem to me to be often enough. I've moved it to be /etc/periodic/daily/305.locate
, to get it to run every night. Not sure if that's a good idea, but I like my /var/db/locate.database
to be more up to date! Oh, and I had to edit the /etc/periodic.conf
file to move it up to a daily ritual. This file overides the /etc/defaults/periodic.conf
file, so it now includes:
# Make the update locate db script run nightly
# 305.locate
daily_locate_enable="YES" # Update locate *daily*!
The other option is the script /usr/libexec/locate.updatedb
. If you run this as root, it complains that it would expose every file on the computer and you probably don't want to do that. The 310.locate script runs it as "nobody", which only picks up files and directories that are world readable, which is less of a security threat. And you can't run it unless you are root anyway, because root can't update the database. So it is easier to just run the periodic script if you need to update it on the fly. But if I run this every night, that should be enough.
No comments:
Post a Comment