How to use the whereis Command

In this tutorial, we will show you how to use the whereis command to find the source, manual, and binary files for certain commands.

How to use the whereis command

The whereis command locates the binary, manual, and source files for a specified command name. It is particularly handy if you need to know the location of certain files for your next project.

Other commands such as find can get similar results but can be much slower and provide less reliable results. I recommend using whereis as it is fast and provides accurate results. It also does not require admin privileges to find the results you require.

Table of Contents

whereis Command Syntax

The basic syntax of the whereis command is right below. I will quickly explain what each part of the command requires underneath the example.

whereis [OPTIONS] [FILE]
  • The OPTIONS section is where you enter any extra option you wish to apply to the command. We touch on some of the different options that you can use a bit further down this page.
  • FILE is where you enter the file or command you intend to use for search. For example, you can simply enter zip to search for the files related to the zip command.

whereis Command Options

There are a few different options that you can use to alter the behavior of the whereis command. Below are some of the options that you can use. I go into a bit more depth on using these options further down the page.

  • -b will search for binaries only.
  • -m will search for manuals only
  • -s will search for sources only.
  • -u is for finding command names that have unusual entries. A command is considered unusual if it has zero or more than one entry for each requested type.
  • -B is similar to -b but lets you limit where the command searches for binaries. After the option, add a space-separated list of directories.
  • -M is limited to manuals and limits the search to specific directories. After the option, add a space-separated list of directories.
  • -S is limited to sources and lets you specify where the command searches. After the option, add a space-separated list of directories.
  • -f terminates the directory list and signals the start of file names. You must use it with -M, -S, -B options.
  • -V or --version displays the version of the command.

Using the whereis Command

The most basic usage of this command is to simply enter whereis followed by the command which you would like to locate the binaries, manuals, and sources.

whereis tar

Below is an example output from the above command.

tar: /usr/bin/tar /usr/share/man/man1/tar.1.gz

Searching for Binary Files

You can limit the command to search for binary files by using the -b option.

whereis -b tar

Below is the result of specifying for binary files only.

tar: /usr/bin/tar

Searching for Manual Files

Using the -m option, you can limit the command to search for just manual files.

whereis -m tar

The example out below shows the manual file for the tar command.

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

Searching for Source Files

You can use the -s option to search for just source files. Below is an example of how you would structure the command.

 whereis -s fs

Below is the output from using the above command.

fs: /usr/src/linux-headers-5.4.0-97-generic/fs

Limit whereis Searches

The whereis command will search a few hard-coded paths for the files you are after. You can further limit the search by specifying the directory you want the command to search.

You can use the -l option to view all the paths that whereis will search by default. It should output a pretty long list of paths.

Whenever you use -B, -M, or -S, you will need to terminate the line with -f followed by the file names you wish to search.

For example, if you want to only search for binary files in the /usr/bin/ directory, you would construct a command similar to the one below.

whereis -B /usr/bin -f tar

Below is the output from using the above command.

tar: /usr/share/man/man1/tar.1.gz /usr/bin/tar

You can search for multiple different file types and in multiple locations. For example, the command below searches for binaries and manuals. It searches /usr/bin and /usr/local/ for binaries. Also, it searches /usr/share/man/man1 for manuals. Lastly, it searches for both tar and zip.

whereis -B /usr/bin /usr/local -M /usr/share/man/man1 -f tar zip

The command above results in the following output.

tar: /usr/bin/tar /usr/share/man/man1/tar.1.gz
zip: /usr/bin/zip /usr/share/man/man1/zip.1.gz

Searching for Unusual Files

The last topic we are going to cover is picking up unusual files. A command is considered unusual if it does not have just one entry per requested type. For example, the following command asks if wget contains more than one manual file.

whereis -u -m wget

As there are multiple manual files, the command outputs the following text.

wget: /usr/share/man/man1/wget.1.gz /usr/share/info/wget.info.gz

More Help

If you require more information on the whereis command and the options you can use, then you can use several reliable commands to get help.

The first is to use the --help or -h options with no other parameters. Below is an example of how to use the whereis command to get help.

whereis --help

You can also use the Linux man command to bring up help documentation. Simply write the following command into the terminal to bring up the whereis man pages.

man whereis

I hope these methods help get you the answer you require. Alternatively, you can try leaving a comment at the bottom of this page.

Conclusion

You should now have a basic understanding of how to use the whereis command on your favorite Linux or Unix distribution. Of course, it is unlikely you will use this command a great deal, but it comes in handy whenever you need it.

If you want to learn more, we have plenty more tutorials covering Linux commands. They are perfect for both beginners and advanced users.

I hope we have accurately covered as much as possible in this tutorial. If you notice anything that requires further explaining, be sure to leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *