Locate Command – Why Locate Command Doesn’t Find Obvious Files


The locate command sounds intuitive. I would expect it to locate files on the filesystem. However, it rarely finds files on the system that are indeed present:

$ locate ipsec.secrets

This gives no results, even when run from filesystem root directory /. The file is indeed present:

$ whereis ipsec.secrets
ipsec: /usr/sbin/ipsec /etc/ipsec.secrets /etc/ipsec.d /etc/ipsec.conf /usr/lib/ipsec /usr/share/man/man8/ipsec.8.gz

Why was locate unable to find this file?

Best Answer

updatedb only runs once a day, you need to run it with root privileges to find recent files.