How To Find Linux Commands and Programs Using Whereis

The 'whereis' command finds programs, source code, and manuals

The Linux Whereis Command

The best method for finding Linux 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."

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.

Other Whereis Switches

Armed with a vague notion as to the location of a program or command, to search for a specific set of directories, 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 is the -b switch, which means a search for the binaries only. The -B switch provides 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 is:

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

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 lists a set of folders to search for the source code.