How come the locate command doesn't find obvious files?

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


If you are not able to locate a file that obviously exists I see only two possibilities:

  1. The file (directory) was created after the last time that the database of locate was updated. By default it is updated once in a day (/etc/cron.daily/mlocate).
    With enough privilege you can fix it forcing an update with

    sudo updatedb
    
  2. The file (directory) was created under a path not scanned by updatedb (case more rare): you can find the keys of the pruned files in the configuration file /etc/updatedb.conf. Search for PRUNENAMES, PRUNEPATHS or PRUNEFS and modify consequently, then update again the database.

    sudo pico /etc/updatedb.conf
    sudo updatedb
    

Of course even without privilege you can still search for the file, for example scanning all the directories and subdirectories starting from a position with something like

find . -name '*ipsec.secrets*'  # to start from the current directory
find / -name '*ipsec.secrets*'  # to start from the root # long long 

Note that whereis has a hard-coded path (where to search for), so may not always find what you're looking for.

Tags:

Locate