- About Us
locatethe missing file. Or
slocateit, depending on your distribution. There is just one problem with using locate or slocate, and that's staying up to date. Here's how they work and how to use them, and a brief tease on rlocate,their nimble, more timely, heir apparent.
slocaterequest has permission to access.
The format of the
locate/slocate is simple:
locate options pattern.
It's a good idea to be as specific as possible with the search pattern, because
locate will list every file name it finds that contains a match. If I use locate to search my SUSE 9.3 desktop system for mono, like this:
It responds with over 400 lines of output. But if I search for libmono instead of simply mono, locate returns only 3 matches.
If you're only interested in how many times the pattern is found, you can specify the
-c option in your search, like this:
locate -c mono
File names in Linux are -- sometimes infuriatingly so users who are new to Unix -- case sensitive. Trying to remember if a file name is whereami, WhereamI, or WhereAmI before searching for it can add frustration to the task. Tell locate that you are an insensitive lout who is totally case insensitive by adding the
-i option to the search, like this:
locate -i whereami
Updating the database
Since updatedb normally runs just once a day, sometimes you need to find a file that has been created since the last update. When that's the case, just enter the command
updatedb as root and let it run. It may take several minutes to complete, or even longer if you have a large number of files to be accounted for. To find out how large your database is, enter the
locate -S, like this:
warthawg@linux:~> locate -S Database<nobr> <wbr></nobr>/var/lib/locatedb is in the LOCATE02 format. Locate database size: 3411612 bytes Filenames: 401444 with a cumulative length of 20196439 bytes of which 38656 contain whitespace, 0 contain newline characters, and 43 contain characters with the high bit set. Compression ratio 83.11%
Bah, that's too klunky!
Having to run the database update program before doing a search in order to have access to the latest files on your system is far from being an elegant solution. Some people just don't want to wait. If that describes you, then you might want to check out a new project called rlocate by Rasto Levrinc. It's based on slocate but with nearly real-time search capabilities.
rlocate -- currently available in a beta release -- requires a Linux kernel at 2.6 or later. It functions as a kernel module which maintain a daily database containing the files and directories created since the last time updatedb was run.
When slocate is executed, both the daily database of new files maintained by the rlocate kernel module and the nightly database of all files are searched. The result is a search that yields results no more than 2 seconds old.
We'll keep an eye on this promising new tool and bring a complete report at a later date. Until then, make use of locate/slocate and updatedb -- and their respective man pages -- to find those files you need, when you need them.