The whereis command is a command-line tool that helps you locate the source or binary and manual pages of a Linux command. This command searches for files in a restricted set of locations (binary file directories, man page directories, and library directories). It is usually used to find executables of a program, its man pages and configuration files.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related system commands queries.
In this context, we shall look into how you can use the whereis command.
What is Whereis command basic syntax ?
The whereis utility takes the syntax shown below:
$ whereis [OPTIONS] filename
Now, let's learn some examples of how to use Whereis command.
1. 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.
2. 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
3. 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
4. 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
5. Search for the source files only
To search for source files only, use the -s option as shown.
$ whereis -s cp
6. 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 two 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
7. 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
How to Check whereis version ?
To check the version of the whereis command, execute:
$ whereis --version
$ whereis -V
How to Get help with whereis utility ?
For additional whereis command options, run the command:
$ whereis --help
[Need help in Installing Software Packages on your Linux System? Contact use today. ]