Update the Database Used by locate


Update the Database Used by locate

updatedb

The first section of this chapter that introduced locate, "Search a Database of Filenames," mentioned that the reason the command is so fast is because it is actually searching a database containing your machine's file and directory names. When locate is installed, it automatically sets itself up to scan your hard drive and update that database, usually in the middle of the night. That's great for convenience, but not so great if you need to find a file you just placed on your computer.

For instance, what if you install Rootkit Hunter, a program that looks for rootkits (used by bad guys to take control of your Linux box), and then you want to look at the files the program has installed? The locate command won't be able to help you because it doesn't know about those files and won't know about them until its database is updated at a later time. You can, however, manually update the database used by locate at any time by running updatedb. Because that command indexes virtually every file and folder on your computer, you need to be root to run it (or use sudo on distributions like K/Ubuntu that discourage root use).

# apt-get install rkhunter # exit $ locate rkhunter $ su - # updatedb # exit $ locate rkhunter /usr/local/rkhunter /usr/local/rkhunter/bin /usr/local/rkhunter/etc 


In the preceding commands, you first install rkhunter, the package name for Rootkit Hunter, and then exit root. You search for rkhunter, but it's nowhere to be seen. You become root again, run updatedb to scan your hard drive and let the locate database know about any changes, and then exit root. Finally, you search for rkhunter with locate again, and this time you're successful.

One thing you should be aware of, however: The speed with which updatedb works is directly proportional to the amount of stuff on your hard drive and the speed of your computer. Got a fast processor, a fast hard drive, and few files? Then updatedb will work quickly. Do you have a slow CPU, 5,400RPM drive, and a million files? Expect updatedb to take quite a while. If you're interested in knowing just how long it takes to run, preface updatedb with the time command, like this:

# time updatedb 


When updatedb finishes, time tells you how long it took to get the locate database squared away. That is useful information to have in your head in case you ever need to use updatedb and you're in a hurry.

Note

The updatedb command is exactly the same as running slocate -u, and updatedb is actually just a link to slocate, as you can easily see for yourself.

$ ls -l /usr/bin/updatedb root root /usr/bin/updatedb -> slocate 





Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net