Home   |   Guides and Tutorials   |   What's New?   |   Comments   |   About
 

locate: Find Files and Directories

by Tammy Fox
Last Modified: Wednesday, 19-May-2004 11:55:35 EDT

Introduction
    The locate command in Linux returns a list of files and directories that contain the keyword you specify. For example, locate kde will return
/usr/bin/kde
/usr/bin/kdehelp
/usr/bin/startkde
etc....
    The locate command can be helpful if you are looking for a file you have created since it will search through all directories on your system. However, it is not the best choice if you are looking for a very small or common string. For example, executing locate ls will bring back much more that you are looking for since every file and directory containing "ls" as a substring will be returned. A better choice for ls would be using whereis ls because it will return the path of the binary and the manual pages.
    The only catch to the locate command is that in order for it to work, the slocate database must be set up. This involves the OS searching through every directory and making a database of the files and directories. This is done through a cron job daily. A cron job is an automated task that is performed according to a schedule such as daily or weekly. The easiest way to populate the database so that the locate command will work is to leave your computer on overnight so that the cron job runs to populate the database. Depending on how large your hard drive is, this could take a considerable amount of time.

Using locate
    The syntax is simple. Type locate keyword where keyword is the file/directory/substring you are looking for.



All Rights Reserved Linux Headquarters © 2000-2007
Linux is a registered trademark of Linus Torvalds
All logos are registered trademarks of their respective owners
Last modified: Wednesday, May 19, 2004