All in the <head> – Ponderings and code by Drew McLellan –

Locate on OS X

A lot of ‘nix based operating systems have a useful tool called locate. Locate is simply a command line tool that helps the user find files. It does this by maintaining an index of the file system that can be searched much more quickly than the file system itself.

On the various Debian and Fedora web servers that I use, I rather take locate for granted. If I need to find the PHP configuration file, for example, I do a quick

locate php.ini

and back comes a list of locations where a file called php.ini exists. Simple, elegant and above all transparent. Except on my mac, that is. Ever since taking delivery of my Powerboko I’ve been hitting a wall each time I tried to use locate. The above search for a php.ini would simply return a fairly unhelpful error about a missing database or something. I never took much notice because, almost by definition, I was doing something more important at the time. If I’m trying to find a file from a shell it’s because something important needs doing.

Well this week I snapped. This helpful page pointed out exactly how to build the database used for indexing – the database the error message was harping on about. Simply put:

sudo /usr/libexec/locate.updatedb

Now, this raises questions for me. Locate has always worked fine on my old iMac, and similarly on our G4 PowerMac at work. Both of these machines run 24/7. Could my lack of a locate database be symptomatic of basic system housekeeping failing to run? Should there be housekeeping tasks running to keep my Powerboko in check, and if so, is there an easy way to confirm what they’re up to?

I think I need me a sysadmin.