Using whereis, whatis and which to learn more about commands in Linux

When you’re trying to find your way around the Linux filesystem and want information about specific commands, the where is, what, and who commands can help. Each provides a different view of the command you are asking about. In this article, I will compare these commands and explain what they tell us and what they don’t tell us.

who

the who command is the simplest of the three. When you use it to ask about a Linux command, it walks your search path looking for executable files by the name you specify. These can be commands available on your system as well as scripts. As long as the files give you execute privilege, they are fine. Here are some examples:

$ which date
/usr/bin/date
$ which init
/usr/sbin/init
$ which loop
~/bin/loop

the who The command does nothing more than show the location of the file. It also stops as soon as it finds a match. The first location in your search path that contains an executable file of the specified name is the one you’ll see listed.

In fgeneral, who is used to display the location of a command so you know which executable you are running when you type the command name. Sometimes it’s important to check that you’re not running a different command than you plan to run. A well-designed search path should help ensure that you are running the expected command. Typically this means having the system directories like /usr/bin, /usr/sbin and /usr/local/bin precede your home directory and your home bin directory.

where is

the where is The command is more liberal in its approach to locating files. It will find the file you are looking for along with the associated commands. On the other hand, it only searches for a command’s binary, source, and manual page files. It does not require the files to be executable and it does not follow your search path. It only searches for particular locations, and as you can see in the example below, one of them could be your bin directory.

Note that the last two files shown in this where is the output are gzipped man pages which are unzipped when you use the male order to read them.

$ whereis date
date: /usr/bin/date /home/shs/bin/date /usr/share/man/man1/date.1.gz
/usr/share/man/man1p/date.1p.gz

what

the what The command does not search for files at all. Instead, it provides a brief explanation of Linux commands. It extracts information from related man pages. Here is an example :

$ whatis date
date (1)             - print or set the system date and time
date (1p)            - write the date and time

In the command above, the what command provides two very brief explanations of the Date ordered. It extracts the first of these descriptions from the main man page and the second from the man page stored in the 1p folder (/usr/share/man/man1p/date.1p.gz). If you want to view these man pages, you can use commands like these:

$ man date
$ man 1p date

Note that the NAME section in the associated man pages includes the brief descriptions shown above.

$ man date | head -4
DATE(1)                          User Commands                         DATE(1)

NAME
date - print or set the system date and time
$ man 1p date | head -10
DATE(1P)                   POSIX Programmer's Manual                  DATE(1P)

PROLOG
       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
       implementation of this interface may differ (consult the  corresponding
       Linux  manual page for details of Linux behavior), or the interface may
       not be implemented on Linux.

NAME
       date — write the date and time

Conclude

the where is, what and who Commands can be useful for making sure you’re running the command you want, finding commands and related files, and giving you very brief descriptions of what the commands can do for you.

Join the Network World communities on Facebook and LinkedIn to comment on topics that matter to you.

Copyright © 2022 IDG Communications, Inc.

Comments are closed.