which vs. whereis vs. whatis in Linux: What Are the Differences?

You might have used which, whereis, and whatis commands on Linux several times. All three commands help you find information about other Linux commands. These commands look similar, but they do have some differences.

Here’s a detailed comparison of the which, whereis, and whatis commands on Linux.

4

The which Command

Some commands have multiple binary executables located in different directories. When you run a command, the shell searches for its executables in the directories specified in the PATH environment variable.

To find out what directories are in the PATH environment variable,open the terminal on Linuxand run the following command:

MacBook and a Dell laptop running ZorinOS next to each other

You can also manuallyadd a directory to your PATH environment variable.

When the shell finds the first executable path, it executes it. Using the which command in Linux, you can identify the path of that executable.

Dell monitor showing Windows 10 desktop

This is useful in scenarios where you have two different versions of the same program or two different programs with the same name installed on your system. Using the which command, you could find which one will be executed first.

Here is the syntax of the which command:

firefox logo with yellow warning symbol

For instance, to check the actual path of thetarcommand, you would type:

This command will display the first executable path i.e./usr/binfound for the tar command in the PATH. This means whenever you run the tar command, the shell executes the binary file located in the/usr/bindirectory.

a person using their laptop while sitting in a lawn

To display all the available executable paths for a command, use the which command with the-aoption:

it’s possible to also display executable paths for multiple commands at once like this:

The whereis Command

The whereis command displays the path of the binary, source, and manual page files associated with the specified command. Unlike the which command, it not only searches for the executable in $PATH but also $MANPATH and other predefined locations.

Without any command-line option, the whereis command displays the binary, source, and manual page files for a command:

To display only the binary file path, use the-boption:

To display only the source file, use the-sflag:

To display only the manual page, use the-moption:

The whatis Command

The whatis command provides a one-line description of a given Linux command. It finds this information from the command’s man page.

For instance, to find what the tar command does, run:

You can also find information about multiple commands simultaneously using:

which vs. whereis vs. whatis: What Are the Differences?

If you are looking for the path of the binary that gets executed when a command is run in the shell, use the which command. Whereas, if you are looking for the source, binary, and man pages for a command, use whereis.

The whereis command lists all the binary executables while the which command only displays the first executable that gets executed when you type the said command in the shell.

The which command performs searches in the PATH variable while the whereis command searches standard Linux directories, including $PATH and $MANPATH.

Finally, the whatis command simply displays a one-line description of a command.

Finding Information About Linux Commands

The which, whereis, and whatis commands help you find information about other Linux commands, like the full path of executables, binary, source, manual pages, and functionality of a command.

Along with whatis, it’s possible to use other commands like apropos, man, info, and help to get detailed information and a better understanding of Linux commands and their functions.

All the essential commands for learning about Linux commands from the command-line

This small feature makes a massive difference.

Don’t let someone else take over your phone number.

Your iPhone forgets what you copy, but this shortcut makes it remember everything.

Anyone with more than a passing interest in motorsports must see these films.

So much time invested, and for what?

Technology Explained

PC & Mobile