Locating Files and Directories

There will be times when you know a file or directory exists but you will not know where to find it. Searching for a file or directory can be easier with the locate command.

With locate, you will see every file or directory whose name contains the search criterion. For example, if you want to search for all files with the word finger in the name, type:

locate finger

The locate command uses a database to locate files and directories that have the word finger in the file or directory name. The search results could include a file called finger.txt, a file called pointerfinger.txt, a directory named fingerthumbnails, and so on. To learn more about locate, read the locate man page (type man locate at a shell prompt).

The locate command works very quickly, as long as the database is up to date. That database is automatically updated on a nightly basis through a cron job. cron is a small program that runs in the background, performing various tasks (such as updating the locate database) at regularly scheduled intervals.


cron is a daemon that executes tasks at regularly scheduled intervals. To read the cron man page, type man cron at the shell prompt.

cron periodically updates the slocate database, which is used to catalog file locations used by the locate commmand. Switching between operating systems and shutting down your machine at the end of the day can interfere with the automatic database update run by cron.

To update the database manually, log in as root (type su at a shell prompt and then enter your root password) and type the command updatedb.

After a few minutes, the slocate database that is used by the locate command will be current.


You can run anacron to have your system execute commands periodically, with a frequency specified in days. Unlike cron, anacron does not assume that the machine is running continuously. Hence, it can be used on machines that are not running 24 hours a day to control daily, weekly, and monthly jobs that are usually controlled by cron.

Refer to the man page on anacron (type man anacron at the command line) for more information.

The Red Hat Documentation Team - Official Red Hat Linux User's Guide
The Red Hat Documentation Team - Official Red Hat Linux User's Guide
Year: 2002
Pages: 223

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