Understanding the whereis
Command in Linux
The whereis
command is a useful tool in the Linux operating system that helps you locate the binary, source, and manual page files for a given command or program. It is particularly helpful when you need to find the location of a specific program or executable on your system.
Syntax and Usage
The basic syntax for the whereis
command is as follows:
whereis [options] [filename]
Here's a breakdown of the different options you can use with the whereis
command:
-b
: Searches for the binary file of the specified program.-m
: Searches for the manual page file of the specified program.-s
: Searches for the source file of the specified program.-u
: Searches for unusual entries, i.e., those that do not have one of the standard prefixes (bin, lib, or src).-B
: Specifies the directories to search for binary files.-M
: Specifies the directories to search for manual page files.-S
: Specifies the directories to search for source files.
To use the whereis
command, simply type the command followed by the name of the program you want to locate. For example, to find the location of the ls
command, you would type:
whereis ls
This will return the location of the binary, source, and manual page files for the ls
command.
Understanding the Output
The output of the whereis
command typically looks like this:
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
The output shows the locations of the binary file (/usr/bin/ls
) and the manual page file (/usr/share/man/man1/ls.1.gz
). If the command has a source file, it will also be listed.
If the whereis
command doesn't find any files for the specified program, it will return an empty output.
Practical Examples
Let's say you want to find the location of the python
command on your system. You can use the whereis
command like this:
whereis python
This might return something like:
python: /usr/bin/python3.9 /usr/bin/python /usr/lib/python3.9 /usr/include/python3.9 /usr/share/man/man1/python.1.gz
This tells you that the python
command is located in the /usr/bin/python3.9
and /usr/bin/python
directories, and the related files (libraries, include files, and manual pages) are located in the other directories listed.
Another example: Let's say you want to find the location of the gcc
compiler. You can use the whereis
command like this:
whereis gcc
This might return:
gcc: /usr/bin/gcc /usr/lib/gcc /usr/share/man/man1/gcc.1.gz
This shows you the location of the gcc
binary, the related library files, and the manual page.
By using the whereis
command, you can quickly and easily locate the files associated with a specific program or command on your Linux system, which can be particularly useful when troubleshooting or trying to understand the structure of your system.