Thursday, December 19, 2013

Update the locate database in OS X Mavericks (10.9)

Greetings, weary tech[no] traveler!

A great command to help find files via the Unix command line is "locate".  Not only is it simple to use:

locate <name of file>   (without the '<' and '>' characters)

but it is quick to return results too.

To do this, the "locate" command relies on a local database to index and, furthermore, return results to you quickly.  Therefore, this local database needs to be updated periodically.

Unlike most other Unix based operating systems, simply running "updatedb" in the OS X (10.9 mavericks) terminal won't work.  So how do we update the locate database for OS X Mavericks (OS 10.9)?  Like this:

1.  Launch terminal

2.  Change your user session to root:
     sudo su -  (then type your password)

3.  Go to the directory /usr/libexec/
     cd /usr/libexec/

4.  Run the following command to update the locate database:
     ./locate.updatedb

After a minute (or 5) your locate database will be updated, and you can continue to use your command line.

It should be noted that this will only work for those who have sudo privileges to their machine.  For good practice, remember to log out of root when you're done (by typing 'exit' at the command line).

No comments: