The whereis command is a command-line tool that helps you locate the source or binary and manual pages of a Linux command. In this brief guide, we will try and provide insights into how you can use the whereis command.
Whereis command basic syntax
The whereis utility takes the syntax shown.
$ whereis [OPTIONS] filename
Let’s now take a few examples.
Search for binary and man pages of a command
Without any options, the whereis utility provides both the path to the binary and the man pages of a Linux command.
Suppose you want to find the binary location of the ls command including the man pages. To achieve his, run the command:
$ whereis ls
From the output, the binary is found in /usr/bin/ path and manual pages in the /usr/share/man/man1/ls.1.gz path.
Let’s take yet another example. To locate the binary path & man pages of cat command, execute:
$ whereis cat
Likewise, the binary is found in /usr/bin/cat path and manual pages in /usr/share/man/man1/cat.1.gz path.
Provide more than one command as an argument
Additionally, you can provide multiple commands as arguments as follows:
$ whereis command1 command2 …
For example, to simultaneously find the binary location and man pages of two commands: pwd and uptime run the command:
$ whereis pwd uptime
Locate the man pages only
Use the -m option o only view the path to the man pages of the command. The example below provides the path to the man pages of the ls command.
$ whereis -m ls
Search for the binary paths only
If you only want to search for the binary paths only and leave out the man pages, use the -b option as shown below.
$ whereis -b ls
Search for the source files only
To search for source files only, use the -s option as shown.
$ whereis -s cp
Limit places that whereis can search for man pages
By default, the whereis utility retrieves all the man pages for a command. To restrict the utility to search in specific man pages, use the -M option followed by the man page and thereafter the -f option followed by the command.
In the example below, the whereis utility searches for man pages of the mkdir command in twp paths: /usr/share/man/man2/mkdir.2.gz and /usr/share/man/man1/mkdir.1.gz.
$ whereis mkdir
Here, we have limited the whereis utility to search for the man pages in the /usr/share/man/man2 path only and ignore the other location.
$ whereis -M /usr/share/man/man2 -f mkdir
Limit places that whereis can search for binaries
Similarly, you can limit the location that whereis searches for binaries. In the command below, whereis searches for binaries in two locations: /usr/bin/pwd and /usr/include/pwd.h.
$ whereis pwd
Using the -B option, as shown, we have restricted the utility to search for the binaries in the /usr/bin path only.
$ whereis -B /usr/bin -f pwd
Check the version
To check the version of the whereis command, execute:
$ whereis --version
$ whereis -V
Get help with whereis utility
For additional whereis command options, run the command.
$ whereis --help
That was a quick overview of the whereis command. Hopefully, you have learned the ropes and can use the utility to locate the binaries and manual pages for various commands.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.