299

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?

Thierry Lam
  • 4,477

5 Answers5

395

It's locate.updatedb on Mac.

sudo /usr/libexec/locate.updatedb

For more information see the locate.updatedb man page.

109

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

Igor Vigasin
  • 1,091
  • 1
  • 7
  • 2
25

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"

Grogs
  • 421
5

If you run locate without first updating the database, you have a chance to see the OS's recommended way by its output.

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.

ikaerom
  • 836
2

Actually you can use the GNU locate & update in mac too.

brew install findutils --with-default-names

export PATH="$(brew --prefix findutils)/libexec/gnubin:$PATH"
export MANPATH="$(brew --prefix findutils)/libexec/gnuman:$MANPATH"

which locate
Iceberg
  • 241
  • 2
  • 3