Finding Server Files with the Locate Command

When you have a dedicated server, it can sometimes be difficult to find the files you need. Tools like “find” and “grep” are always at your disposal, but as they dig through your mountain of data, they can take a good deal of time. Fortunately, Linux and Unix servers have a tool called “locate” that you can use to search a pre-indexed database listing all your files.

In order to use locate for the first time, you must first make sure your database is up-to-date. To update the database, run the following command:

updatedb

This may take quite a while, depending on the number of files you have, but when it is complete, all of your current files will be easily searchable from the database. To search for a file, all you have to do is type “locate” followed by the filename. For example:

locate photos.html

If you are not sure what the whole name of the file is, you can use partial names. For example:

locate phot

Finally, if you want to make sure updatedb runs regularly, you need to setup a cron job. Some operating systems do this by default. Because it can be resource-heavy, I recommend you make sure updatedb runs when web traffic on the server will be at its lowest for your region.











Comments: