Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I want to use the locate command on a Linux machine, I usually run sudo updatedb first to update the database. I can run the locate command on OS X 10.5 but I can't find updatedb. What's the corresponding updatedb for the mac?

share|improve this question
    
Well upatedb and locate are nice things but they require to run updatedb regularly (either updatedb runs regularly and this slows down your system at inconvenient times, or locate shows references to files which are not there anymore). So I think that instead of setting up locate/updatedb it would perhaps be better to get familiar with (the far more powerful) find. –  amo-ej1 Feb 16 '10 at 16:43
3  
While find is useful for lots of things, it does need to go through the filesystem each time. If you can narrow down the places where you are looking, that's fine. The advantage of locate is that keeps its own database, and so doesn't need to search each time. This is especially important with large and/or remote filesystems. I think that each has its place. –  KeithB Feb 16 '10 at 17:00
    
When first running locate on an OS X box it tells you to run sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist. –  Török Gábor Feb 17 '10 at 15:24
5  
Depending on what you need to use locate for, you might find it more convenient to use the command line interface to Spotlight, mdfind, since the Spotlight database is nearly always up-to-date, and offers a lot more functionality than locate. man mdfind –  Paul R Feb 17 '10 at 16:09

3 Answers 3

up vote 104 down vote accepted

It's locate.updatedb on Mac.

sudo /usr/libexec/locate.updatedb

For more information see the locate.updatedb man page.

share|improve this answer
4  
That man page also claims: It is typically run once a week by the /System/Library/LaunchDaemons/com.apple.locate.plist job. (And man locate tells one about that script: /usr/libexec/locate.updatedb Script to update the locate database) –  Arjan Feb 16 '10 at 15:29
2  
+1 man pages are an indispensable resource. –  John T Feb 16 '10 at 15:30
3  
@Arjan : It should be run once a week, but the default it's disabled and the time when it should be done is 3am on Sundays (or something similar), which isn't really useful :) –  Studer Feb 16 '10 at 15:36
    
On linux I usually run sudo ionice -c3 updatedb which tells updatedb to share the i/o controller nicely (io nice) but I don't think this command is available on mac. I also miss having the -r regular expression flag which can be used with the GNU locate, although I'm not sure I want to use homebrew and install the GNU locate mentioned by @Grogs –  cwd Jun 16 '12 at 12:41
    
Thanks, I'm gonna make an alias for that ! –  Zulu Sep 6 '12 at 16:25

You can do sudo ln -s /usr/libexec/locate.updatedb /usr/local/bin/updatedb to make the updatedb command available.

share|improve this answer

Personally, I just installed findutils (use MacPorts or Homebrew).

Then you have GNU locate and updatedb.

updatedb won't work without sudo.

Personally I prefer to have a per user locatedb though; if you sudo other users will know the names/locations of all your files.

I have a cron job to run:

updatedb --localpaths='/Users/grogs' --output='/Users/grogs/tmp/locatedb'

And in my .zshrc .bashrc/.bashprofile:

export LOCATE_PATH="~/tmp/locatedb"

share|improve this answer
    
Brew-installing findutils on OS X Mavericks gave me a gupdatedb command, not an updatedb one. Unfortunately this command gave me an error described here (where your SO answer is referenced). Ultimately I've aliased updatedb to LC_ALL=’C’ sudo updatedb as a workaround, but I don't know if this is a long-term solution. –  David Rivers Dec 13 '13 at 19:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.