Missing 'locate' in Snow Leopard

Apr 1, 2010

When I upgraded to Snow Leopard a few months ago I found out quite quickly that locate didn’t work on the command line. Why locate is missing I don’t know, maybe find was supposed to replace it. But find doesn’t look deep enough into the system files to be useful for me. I finally got round to looking into the problem.

Using locate file.txt get’s us this: WARNING: The locate database (/var/db/locate.database) does not exist. To create the database, run the following command:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

Please be aware that the database can take some time to generate; once the database has been created, this message will no longer appear. Ok. So it’s easy enough to run:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

But that didn’t do anything for me. Locate still threw the same error and top didn’t reveal any processes that appeared to be working overtime to build the database(\*see below). Trying the launchctl load command again says it’s already loaded, and using start com.apple.locate via a launchctl daemon gets a start error:No such process message. So I opened /System/Library/LaunchDaemons/com.apple.locate.plist which revealed the task that actually does the work is locate.updatedb, so I tried:

sudo /usr/libexec/locate.updatedb

Which successfully built the database and locate now works. The one question remaining is wether the database will be updated automatically every Saturday at 3am as the plist file suggests. Maybe not, if the Disabled in the plist is to be believed - so I’ve blindly switched it to false and am hoping for the best.

* I ran through this process again on a second machine, and it appears that I jumped the gun on this as I just left the machine be for half an hour and came back to it and the database worked.


Comments

gremoz - Apr 4, 2010

Hi, please check command “sudo ./usr/libexec/locate.updatedb”. Its looks like, you’ve got an error in the path, it should be without “.”


Simon - May 2, 2010

Thanks for the responses, and the explanation regarding using my originally posted, and problem causing:

sudo ./usr/libexec/locate.updatedb

Which I’ve now updated to avoid any more issues.


Simon - Apr 6, 2010

@greymoz - I’ve always used a . to tell the shell I want to execute the item I’m referencing. Is there another/better way to do this?


Nicolas - May 1, 2010

Thanks for this, I was wondering what happened to my locate command.

By the way, with the ./, your command will only work when you’re in the root directory. The ‘./’ tells it to execute relative to the working directory. If you give a directory structure though, it’ll automatically attempt to execute what you provide.

so

/usr/libexec/locate.updatedb will execute the command despite whatever your working directory

cd /usr libexec/locate.updatedb will also execute locate.updatedb.

cd /usr/libexec ./locate.updatedb will execute only if locate.updatedb is in your working directory


Rémy - May 2, 2010

Just like you said, the . indicates the shell to look for the specified path from the working directory.

The command you provided, sudo ./usr/libexec/locate.updatedb, should therefore only work if your current working directory is the /, namely the root.

I used the following command : sudo /usr/libexec/locate.updatedb. It’s an absolute path, contrary to yours which is a relative path.


Bartholomew Bates - Jun 2, 2010

By the way, with the ./, your command will only work when you’re in the root directory. The ‘./’ tells it to execute relative to the working directory. If you give a directory structure though, it’ll automatically attempt to execute what you provide. +1