The command is:
man updatedb for more details.
On OSX this is:
Which can be linked with:
sudo ln -s /usr/libexec/locate.updatedb /usr/local/bin/updatedb
Seems silly to have to make a symbolic link for a standard unix command, but there it is.
While the answer:
is technically correct, it is almost never a good idea to run
updatedb on a command line by itself, if there is also a cron job installed. Depending on the Unix flavor the cronjob contains locking provisions and any amount of configuration which is not covered by the standalone
If the locate database needs to be updated frequently, it is definitely worth the effort to determine the proper cron job for a specific host and run it manually.
Depending on the administrator, the cronjob for
updatedb may be hidden in various locations. So a simple brute-force attempt to find the cron job would be:
( sudo crontab -l > /tmp/crontab.root; ( echo /tmp/crontab.root; ls -1d /etc/*cron* /etc/*cron*/* ) | tr 'n' ' ' | xargs -0 -r -e grep -nH -e updatedb; rm -f /tmp/crontab.root ) 2>/dev/null
which shows the following result on one of my Ubuntu systems:
/etc/cron.daily/mlocate:5:[ -x /usr/bin/updatedb.mlocate ] || exit 0 /etc/cron.daily/mlocate:21:flock --nonblock /run/mlocate.daily.lock $IONICE /usr/bin/updatedb.mlocate
The correct command to update the locate database in this case is therefore
A more systematic approach is to determine the package which provides
E.g., on an OS with apt/dpkg packaging you can find which flavor of locate is installed with:
dpkg -S locate | grep /bin/
In my case it is:
To see, which cron job if any is responsible, run:
dpkg -L mlocate | grep cron
Which in my case shows:
To update the database, run the cron job as root:
If there is no cronjob, and updatedb by itself does not work, try finding your installed flavor with:
dpkg -L mlocate | grep /bin/
NB: If you downvote this answer, be so nice and let me know why the hobbyist answer is considered better.