How To Find Linux Commands and Programs Using Whereis

The Linux Whereis Command

Have you ever tried to find the location of a command, program or application but didn't know where to look? The best method for finding programs is the whereis command.

According to the man pages, "whereis locates the binary, source, and manual files for the specified command names. The supplied names are first stripped of leading path-name components and any (single) trailing extension ... Whereis then attempts to locate the specified desired program in the standard Linux places, and in the places specified by $PATH and $MANPATH."

In essence, therefore, the whereis command can find the source code, manuals, and the location of a program.

How to Find a Program Using Whereis

Linux whereis output

Let's try it with telnet:

whereis telnet

The output from the above command is as follows:

telnet: /usr/bin/telnet /urs/bin/telnet.netkit ...

If you just want to find the location of the program you can use the switch -b as follows:

whereis -b telnet

This returns the following result:

telnet: /usr/bin/telnet /usr/bin/telnet.netkit ...

Alternatively, if you just want to know the location of the manuals you can use the -m switch.

whereis -m telnet

The result for the above command is as follows:

telnet: /usr/share/man/man1/telnet.1.gz

Finally, you can limit the search to just the source code by using the -s switch. However, in some cases, the source code isn't available, in which a blank line is returned.

There are other switches available for the whereis command including -u which looks for unusual files.

The manual says the following about the -u switch:

A command is said to be unusual if it does not have just one entry of each explicitly requested type. Thus 'whereis -m -u *' asks for those files in the current directory which have no documentation file, or more than one.

Essentially if you have more than one manual located on your system or the program you are running appears in more than one place it will be returned.

Other Whereis Switches

If you have a vague notion as to the location of a program or command and you want to search a specific set of directories you can use the -B switch to search for binaries in a specified list.

For example:

whereis -b -B /usr/bin -f telnet

The above command has a few parts to it. First of all there is the -b switch which means we are looking for the binaries only (the programs themselves). The -B switch is used to provide a list of places to search for the binaries and the list of folders is terminated by the -f switch. Therefore in the command above the only directory searched is /usr/bin. Finally the telnet after the -f tells whereis what it is looking for.

An alternative to the -B switch is -M which searches a specific set of folders for manuals.

The command line for the -M switch would be as follows:

whereis -m -M /usr/share/man/man1 -f telnet

The logic is the same for the -M as it was for -B. The -m tells whereis to look for manuals, the -M tells whereis that a list of folders is coming in which it should look for manuals. The -f terminates the list of files and telnet is the program that the whereis command is going to look for manuals for.

Finally the -S switch can be used to list a set of folders to search for the source code.