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?
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: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
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.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
Note that
whereis
has a hard-coded path (where to search for), so may not always find what you're looking for.Being somewhat lazy and not wanting to run
sudo updatedb
and, since I have a computer that can work for me, it runssudo updatedb
every 15 minutes so I don't have to.Use
sudo crontab -e
and find this line:insert below it:
Then press Ctrl+O to save the file (write it Out) and then Ctrl+X to eXit.
If you've just created the files in the last 15 minutes though you will still need to run:
... to manually update the indices used by
locate
command.My solution was super fast (but maybe not optimal since your
sudo updatedb
command will take more time). However, you won't miss any file anymore, even if you have multiple partitions (this is handy for me).I opened the configuration file of
updated
(you needsudo
privileges to save the following file):nano /etc/updatedb.conf
I then commented (adding a
#
at the beginning of the line) all the lines starting with:PRUNENAMES
PRUNEPATHS
PRUNEFS
Save the file (
CTRL+O
,ENTER
,CTRL+X
).I hope this helps someone else.