update locate database for Mac Os X

Posted by: barbara | Date: Jun 05, 2008 | Updated: Jun 05, 2008 | Category: Mac OS X    

Here's one of those little things I do frequently, but never remember the command.

The 'locate' command searches a file name database that is updated weekly (I think the default update time is 4:30 am every Saturday morning, but only if your Mac is switched on then, which mine never is).

If you try to run 'locate' on a database that isn't current, files created more recently than the last update will not be found, and deleted files will be found erroneously.

To update the database manually use the following command:

sudo /usr/libexec/locate.updatedb
Awesome. =) I'm running that now. Gives a kinna-scary notice: >>> WARNING >>> Executing updatedb as root. This WILL reveal all filenames >>> on your machine to all login users, which is a security risk. A little poking around in the man page for locate revealed this, at the end (under BUGS): The locate program may fail to list some files that are present, or may list files that have been removed from the system. This is because locate only reports files that are present in the database, which is typ- ically only regenerated once a week by the /etc/periodic/weekly/310.locate script. Use find(1) to locate files that are of a more transitory nature. 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. The locate database is not byte order independent. It is not possible to share the databases between machines with different byte order. The cur- rent locate implementation understands databases in host byte order or network byte order if both architectures use the same integer size. So on a FreeBSD/i386 machine (little endian), you can read a locate database which was built on SunOS/sparc machine (big endian, net). The locate utility does not recognize multibyte characters.
Comment by VDG on Jun 12, 2009:
when I update the database, it gives me the same message as David Christian. And after when I try to use the locate command, it gives me that error : locate: `/var/db/locate.database': No such file or directory
Just did a similar Database Update on my Mac. Worked well.