Update locate database on OS X (updatedb)

In order to update "locate" database on OS X, some people suggest to create a symlink:


sudo ln -s /usr/libexec/locate.updatedb /usr/local/bin/updatedb

However, this method can create an erroneous output if you are in directory with a specific permission e.g.

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
find: .: Permission denied


The better method would be to create a bash script /usr/local/bin/updatedb:

  #!/bin/bash
  pushd . > /dev/null
  cd /usr/libexec
  echo "Updating locate database..."
  sudo ./locate.updatedb
  echo "Updating complete!"
  popd > /dev/null


Make it executable: sudo chmod +x /usr/local/bin/updatedb

Now you can just run «sudo updatedb», in order to update «locate» database.

Comments (0)

RSS Collapse / Expand

Only registered and authorized users can leave comments. Login or Register