Difference between which, whereis and whatis in Linux
You may have used which, whereis and whatis commands on Linux several times. All three of these commands help you find information about other Linux commands. These commands look similar, but they have some differences.
Here is a detailed comparison of which, whereis and whatis commands on Linux.
which . command
Some commands have multiple binary executables located in different directories. When you run a command, the shell searches for its executable files in the directories specified in the PATH environment variable.
To find out what directories are in the PATH environment variable, open a terminal on Linux and run the following command:
echo $PATH
Tip : You can also manually add directories to the PATH environment variable.
When the shell finds the first executable path, the shell executes it. Using the which command in Linux, you can determine the path of that executable.
This is useful in cases where you have two different versions of the same program or two different programs with the same name installed on your system. Using which command you can find which command will be executed first.
Here is the syntax of which command:
which [option] [command]
For example, to check the actual path of the tar command, you would type:
which tar
This command will show the first executable path i.e. /usr/bin found for the tar command in the PATH. This means that whenever you run the tar command, the shell will execute the binary located in the /usr/bin directory.
To display all available executable paths for a command, use the which command with the -a option :
which -a tar
You can also display the execution paths for multiple commands at once as follows:
which [command1] [command2] [command3]
command whereis
The whereis command displays the path of the binary, the source, and the manual page associated with the specified command. Unlike the which command, it searches not only the executable in $PATH but also $MANPATH and other predefined locations.
Without any command line options, the whereis command displays the binaries, source and manual pages for a command:
whereis tar
To display only the binary file path, use the -b option :
whereis -b tar
To display only the source file, use the -s flag :
whereis -s tar
To display only the manual page, use the -m option :
whereis -m tar
whatis . command
The whatis command provides a one-line description of the given Linux command. It finds this information from the command's manual page.
For example, to find out what the tar command does, run:
whatis tar
You can also find information about multiple concurrent commands using:
whatis ls cp mkdir cat head
Difference between which, whereis and whatis in Linux
If you are looking for the path of the binary to be executed when a command is run in the shell, use the which command. If you are looking for sources, binaries and manual pages for a command, use whereis.
The whereis command lists all binary executables while the which command only shows the first file that is executed when you enter said command in the shell.
The which command searches the PATH variable, while the whereis command searches standard Linux directories, including $PATH and $MANPATH.
Finally, the whatis command only shows the one-line description of the command.
You should read it
- Search for files and directories in Linux using the command line interface
- How to use the which command in Linux
- 20+ essential Linux security commands
- How to use the stat command on Linux
- Instructions for using pstree command on Linux
- The Cat command in Linux
- The dd command in Linux, How to use the dd command
- Del command in Windows
- How to use the history command in Linux
- 11 uses of ps command in Linux
- Tail command in Linux
- Instructions for using find command in Linux
Maybe you are interested
What to do when open command window here does not appear?
How to switch users on the Linux command line
How to fix Mac Homebrew error 'zsh: command not found: brew'
What is the Command key on Windows?
How to use read command in Linux
Basic Linux commands everyone needs to know - Operations on Linux are much faster