Given the name of a program, which looks through the directories in your search path, in order,
locates the program. If the search path includes more than one program with the specified name, which displays the name of only the first one (the one you would run).
The whereis utility looks through a list of standard directories and works independently of your
search path. Use whereis to locate a binary (executable) file, any manual pages, and source code
for a program you specify; whereis displays all the files it finds.
caution
Both the which and whereis utilities report only the names for commands as they are found on the disk; they do not report shell builtins (utilities that are built into a shell;
When you use whereis to try to find where the echo command (which exists as both a utility program and a shell builtin) is kept, you get the following result:
$ whereis echo
echo: /bin/echo /usr/share/man/man1/echo.1.gz
The whereis utility does not display the echo builtin. Even the which utility reports the wrong
information:
$ which echo
/bin/echo
Under bash you can use the type builtin (page 445) to determine whether a command is a builtin:
$ type echo
echo is a shell builtin
whereis examples
whereis
The whereis command performs an incredibly useful function: It tells you the paths for a command's executable program, its source files (if they exist), and its man pages. For instance, here's what you might get for KWord, the word processor in the KOffice set of programs (assuming, of course, that the binary, source, and man files are all installed):
$ whereis kword
kword: /usr/src/koffice-1.4.1/kword /usr/bin/kword/usr/bin/X11/kword usr/share/man/man1
/kword.1.gz
The whereis command first reports where the source files are: /usr/src/koffice-1.4.1/kword. Then it informs you as to the location of any binary executables: /usr/bin/kword and /usr/bin/X11/kword. KWord is found in two places on this machine, which is a bit unusual but not bizarre. Finally, you find out where the man pages are: /usr/share/man/man1/kword.1.gz. Armed with this information, you can now verify that the program is in fact installed on this computer, and you know now how to run it. If you want to search only for binaries, use the -b option.
$ whereis -b kword
kword: /usr/bin/kword /usr/bin/X11/kword
If you want to search only for man pages, the -m option is your ticket.
$ whereis -m kword
kword: /usr/share/man/man1/kword.1.gz
Finally, if you want to limit your search only to sources, try the -s option.
$ whereis -s kword
kword: /usr/src/koffice-1.4.1/kword
The whereis command is a good, quick way to find vital information about programs on the computer you're using. You'll find yourself using it more than you think.
source :- scott granneman
No comments:
Post a Comment