How to Use the whereis Command in Linux to Locate Binaries and Manual Pages

When you type a command like python or grep into a Linux terminal and press Enter, the operating system instantly executes the program. It knows exactly where the executable files for those commands are located on the hard drive because it searches through the directories listed in your system’s $PATH variable. However, if you are troubleshooting a script, modifying system permissions, or trying to figure out if you are running the system-default version of Python or a custom-installed version, you need to know the exact absolute file path of the executable. The whereis command is a built-in Linux utility designed specifically to locate the binary executable, source code, and manual page files for any given command.

Executing the whereis Command

Using whereis is incredibly straightforward. You simply pass the name of the command or program you are searching for as an argument.

  1. Open your terminal application.
  2. Type the command followed by the program name: whereis python3
  3. Press Enter.

The output will typically look like this:

python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3 /usr/share/man/man1/python3.1.gz

Understanding the Output

The whereis command returns all relevant files it finds, separated by spaces. It organizes them logically:

  • Binaries (Executables): The first path listed is almost always the actual executable binary. In the example above, /usr/bin/python3 is the program that runs when you type the command.
  • Libraries and Configuration: It will also list directories where the program stores its libraries or global configuration files (e.g., /usr/lib/python3).
  • Manual Pages: The final path ending in .gz is the compressed manual file that the system reads when you type man python3.

Filtering the Results

If you are writing a bash script and only want the path to the executable binary, you do not want to parse the extra configuration paths or manual pages out of the output string. You can use flags to force whereis to return only specific types of files.

  • Search for Binaries Only (-b): whereis -b ssh Output: ssh: /usr/bin/ssh
  • Search for Manual Pages Only (-m): whereis -m ssh Output: ssh: /usr/share/man/man1/ssh.1.gz
  • Search for Source Code Only (-s): If the source code packages are installed on your system, the -s flag will locate them. (If they are not installed, it will return nothing).

How whereis Differs from the which Command

You may also be familiar with the which command. While they seem similar, they operate differently.

The which command only searches your $PATH environment variable. It tells you exactly which single binary will execute if you type the command right now. If you have two versions of Python installed, which only shows the one that takes priority.

The whereis command searches a broader set of standard Linux directories (including /usr/bin, /usr/sbin, /lib, and manual directories) regardless of your current $PATH variable. It will show you every installation of the binary it finds in those standard locations, along with its documentation, providing a much more comprehensive view of how the software is installed on your system.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.