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
May be interested
- How is Arch Linux different from other Linux versions?arch linux is arguably the most misunderstood linux distribution. many people find arch difficult to install and maintain.
- 14 interesting Linux commands in Terminalterminal is a very powerful tool, but it can become 'interesting' through a few bash commands that quantrimang will introduce to you later. let's follow up and find out because some commands are quite useful.
- 18 Interesting Linux Commands in Terminalterminal is a very powerful tool, but it can be made 'interesting' through a few bash commands that tipsmake.com will introduce to you below. let's follow and learn because some commands are quite useful.
- Compare the most popular Linux distributions todayit can be said that linux is not a complete operating system, it is just a kernel operating system, which is the foundation for developing other operating systems.
- Instructions for using pstree command on Linuxpstree is a powerful and useful command to display processes running in linux. like the ps command, it shows all the processes that are currently active on your login system. the main difference is that when running the pstree command, processes are organized into tree sorting instead of lists like using the ps command.
- 7 best Linux distributions based on Red Hatred hat became the largest open source company in the world before it was acquired by ibm, and red hat enterprise linux was its main product.
- Difference between Web 2.0 and Web 3.0today, a new term is circulating, called web 3.0 (or web3). but what is web 3.0 and is it much different from web 2.0?
- Moving from Windows to Linux, I understood the difference between 'technology' and 'reality'.there are things that make us feel really happy, feel like we truly own technology in our hands. and sometimes, along with that sense of 'ownership' are wasted hours.
- The Difference Between 4K and 8Kthe main difference between 4k and 8k lies in the number of pixels included in the resolution.
- What is the difference between PCIe 3.0, PCIe 4.0 and PCIe 5.0?intel 12th gen alder lake cpus are rumored to come with a new version of pci express 5.0. the question arises: what is the difference between pcie 5.0 and the existing versions? is it worth our attention?