locate (find files by name)

Let's say you're looking for a file called resolv.conf and you have no idea where it might be on your system. You could try a search using →find / -iname resolv.conf, but searching your whole file system starting from / is likely to take a long time. locate to the rescue! This command searches an index or database of all the files present on your system, which is much faster than crawling the file system itself using find. Call locate like this:

locate resolv.conf

The search should quickly turn up the desired file, /etc/resolv.conf. If not, locate's file index might be out of date. For locate to work properly the index needs to be updated regularly, otherwise new files added to the system will not be found. You can update locate's index by typing:

sudo updatedb

However, this should only be necessary if you added a lot of files to your system in the last couple of hours, because most Linux distributions run updatedb automatically once a day (without the user even noticing it). If you want to know when locate's index was last updated, have a look at the database file mlocate.db using →ls -l:

... May 24 19:40 /var/lib/mlocate/mlocate.db

The exact location of mlocate.db may differ on your system. The file is likely to be somewhere under /var/lib/.