Datasheet
22
Phase 1
Working on the Command Line
In addition to the -name criterion, you can search for files in various other ways, such as
by permissions (-perm), file size (-size), and owner (-user). The man page for find details
these options; consult it for more information.
Using locate
The locate command is much less flexible than find, but it’s also much faster. To use
locate, type the command name followed by the name of the file you want to find:
# locate whatis
The locate command works by searching a database that it maintains. (If this database is
out-of-date, typing updatedb as root will update it.) The locate command returns the names
of all the files in the database whose names contain the string you specify. Thus, this command
is likely to return the names of many files that merely contain the string you specify, such as
makewhatis and whatis.1.gz. This can be a real problem if you’re searching for a file with
a short name. The locate database also doesn’t include every directory on the computer, but
it does include enough directories that it’s likely to be a useful tool.
Many Linux distributions actually use a program called slocate rather than
locate. The slocate program is a more security-aware version of the pro-
gram; it checks who’s calling the program and adjusts its output to remove
references to files to which the user shouldn’t have access. Distributions that
use slocate typically create a link called locate so that you can call the pro-
gram using this more common name.
Using whereis
The whereis program searches for files in a restricted set of locations, such as standard binary
file directories, library directories, and man page directories. This tool does not search user
directories or many other locations that are easily searched by find or locate. The whereis
utility is a quick way to find program executables and related files like documentation or con-
figuration files.
The whereis program returns filenames that begin with whatever you type as a search cri-
terion, even if those filenames contain extensions. This feature often turns up configuration
files in /etc, man pages, and similar files. To use the program, type whereis followed by the
name of the program you want to locate. For instance, the following command locates
whatis:
# whereis whatis
whatis: /usr/bin/whatis /usr/X11R6/bin/whatis /usr/bin/X11/whatis
/usr/man/man1/whatis.1.gz /usr/share/man/man1/whatis.1.gz
The result shows the whatis executable (/usr/bin/whatis), links to it in other directo-
ries, and the man page for whatis, including a link in a second location. (Your system might
83484.book Page 22 Monday, September 18, 2006 8:58 AM










