What can you find out in Linux ask what, where and what is?


The Which, where is and What is Commands on a Linux system provide information about commands. They provide related, but not identical, information. In this post we will review the differences and provide a script to get information available from all three commands. We’ll also examine some example commands for viewing secondary (ie not Section 1) man pages.


The Which Command shows you the file system location for a command’s executable. This is the file that will be read and executed when you enter the command name.

$ which date
$ which shutdown

The Which command will also report on your aliases and show you the commands that invoke them.

$ which recent
alias recent=’ls -ltr | tail -10’

where is

To like Which, the where is Command will show you the file = system location for the executable associated with a command, but it will also tell you where the man (Manual) pages are located.

In the example below, there are two or three man pages for each of the commands.

$ whereis date
date: /usr/bin/date /usr/share/man/man1/date.1.gz /usr/share/man/man1p/date.1p.gz
$ whereis shutdown
shutdown: /usr/sbin/shutdown /usr/share/man/man2/shutdown.2.gz /usr/share/man/man3p/shutdown.3p.gz /usr/share/man/man8/shutdown.8.gz

What is

The What is Command contains brief descriptions of the commands. Each description is assigned to one of the man pages for that command, as shown in the following example.

$ whatis date
date (1)             - print or set the system date and time
date (1p)            - write the date and time
$ whatis shutdown
shutdown (2)         - shut down part of a full-duplex connection
shutdown (3p)        - shut down socket send and receive operations
shutdown (8)         - Halt, power-off or reboot the machine

To view the primary man page for any command, simply type “man” plus the name of the command; B. “man date”. Add the section of the man page (for example, “man 3p shutdown”) for a different section of the man page. Notice that at the top of the man page you will see a confirmation of the command and the relevant man page section:

$ man 3p shutdown

SHUTDOWN(3P)               POSIX Programmer’s Manual              SHUTDOWN(3P)

       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.

       shutdown—shut down socket send and receive operations


       int shutdown(int socket, int how);

(The above output has been cut off.)

Man pages are divided into up to 9 sections:

1   Executable programs or shell commands
2   System calls (functions provided by the kernel)
3   Library calls (functions within program libraries)
4   Special files (usually found in /dev)
5   File formats and conventions, e.g. /etc/passwd
6   Games
7   Miscellaneous (including macro packages and conventions), e.g.
    man(7), groff(7)
8   System administration commands (usually only for root)
9   Kernel routines [Non standard]

Your search path is important

You can do all three Which, where is and What is Commands whenever you want to know a little more about the commands you are executing and where they are stored on your system. When you run a command and get an unexpected response, it can be important to check which executable you are dealing with.

$ date
No thanks. I’m not into dating.
$ which date

Hm! Something is wrong in this example. While it is very unlikely that you will get such a response, it is possible to have two executables on the same system with the same name. In this case, it depends, at least in part, on your search path which one you end up doing. Your personal bin directory probably should Not sit in the first position in your $ PATH variable and shouldn’t be “.” (current position) because of the risk of executing a different command than you intended.

$ echo $PATH

Use all three commands

The following script executes all three commands and displays the output in a useful format. In fact, it can take a list of commands and display the command output to examine each of them.



if [ $# == 0 ]; then     # if no arguments provided, prompt user
    echo -n “What command(s) are you asking about?> “
    read args

for cmd in `echo $args`  # for each command entered
    echo “$cmd”
    echo -n “executable: “
    which $cmd
    echo -n “all files: “
    whereis $cmd | sed “s/$cmd: //“
    echo “function(s):”
    whatis $cmd
    echo “====================================================================”

Here is an example of the script running for two commands:

$ about date shutdown
executable: ~/bin/date
all files: /usr/bin/date /home/shs/bin/date /usr/share/man/man1/date.1.gz /usr/share/man/man1p/date.1p.gz
date (1)             - print or set the system date and time
date (1p)            - write the date and time
executable: /usr/sbin/shutdown
all files: /usr/sbin/shutdown /usr/share/man/man2/shutdown.2.gz /usr/share/man/man3p/shutdown.3p.gz /usr/share/man/man8/shutdown.8.gz
shutdown (2)         - shut down part of a full-duplex connection
shutdown (3p)        - shut down socket send and receive operations
shutdown (8)         - Halt, power-off or reboot the machine

Wrap up

The Where, where is and What is Commands provide useful command summaries that show where the executable files are and point to the appropriate man pages. The what command can also check which executable you are using when you enter a command name.

Consult the man pages to learn about all of the options available and for a more detailed explanation of how these commands work.

Join the Network World communities on Facebook and LinkedIn to comment on topics that come first.

Copyright © 2021 IDG Communications, Inc.

Source link


Leave A Reply