Linux whereis Command

Locate Binary, Source, and Manual Pages - 10 Practical Examples with Detailed Explanations

Example 1

Find Binary, Source, and Manual

$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
Locates the binary executable, source code, and manual page files for a command. Shows the full paths to each. This is the default behavior - searches standard system directories for all three types of files.
Output Format: command: binary_path source_path manual_path
Example 2

Find Binary Only

$ whereis -b grep
grep: /usr/bin/grep /bin/grep
Searches only for binary executables using the '-b' option. Ignores source files and manual pages. Useful when you only want to know where the executable is located, especially if there are multiple versions.
Quick Location: Fast way to find just the executable path
Example 3

Find Manual Pages Only

$ whereis -m bash
bash: /usr/share/man/man1/bash.1.gz
Searches only for manual pages using the '-m' option. Shows where the man page documentation is stored. Helpful when you want to verify documentation exists or locate manual files for editing or backup.
Documentation: Man pages are typically compressed with gzip
Example 4

Find Source Files Only

$ whereis -s gcc
gcc:
Searches only for source files using the '-s' option. Most system commands don't have source files in standard locations, so this often returns empty results unless you've installed development packages or built from source.
Development: More useful when working with locally compiled software
Example 5

Search Multiple Commands

$ whereis ls grep sed awk
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz grep: /usr/bin/grep /bin/grep /usr/share/man/man1/grep.1.gz sed: /usr/bin/sed /bin/sed /usr/share/man/man1/sed.1.gz awk: /usr/bin/awk /usr/share/man/man1/awk.1.gz
Searches for multiple commands at once. Simply list all command names as arguments. Much faster than running whereis multiple times. Perfect for checking a group of related commands or verifying tool availability.
Batch Query: Efficient way to locate multiple commands
Example 6

Limit Search to Specific Directories

$ whereis -B /usr/local/bin -f python
python: /usr/local/bin/python
Restricts binary search to specific directories using '-B' followed by directory paths and '-f' to mark the end of the directory list. Useful when you have multiple versions installed and want to check specific locations.
Version Control: Find specific installations when multiple versions exist
Example 7

Find Unusual Entries

$ whereis -u ls
Lists commands that have unusual entries using the '-u' option. A command is considered unusual if it doesn't have just one entry of each requested type. Most standard commands return nothing as they have exactly one binary and one man page.
Unusual: Multiple binaries, missing man pages, or other anomalies
Example 8

Compare whereis and which

$ whereis python $ which python
python: /usr/bin/python /usr/bin/python3 /usr/share/man/man1/python.1.gz /usr/bin/python
Demonstrates the difference between whereis and which. whereis finds all locations in standard directories, while which shows only the executable that would run based on your PATH. whereis is broader, which is more specific to your environment.
Use Case: whereis for all locations, which for active executable
Example 9

Find System vs User Binaries

$ whereis -b bash ssh vim
bash: /usr/bin/bash /bin/bash ssh: /usr/bin/ssh vim: /usr/bin/vim
Helps identify whether binaries are in system directories. Shows if commands exist in multiple locations like /bin and /usr/bin. Useful for understanding your system layout and finding duplicate installations.
System Layout: /bin and /usr/bin are often symlinked on modern systems
Example 10

Check Command Availability

$ whereis docker $ whereis nonexistent
docker: /usr/bin/docker /usr/share/man/man1/docker.1.gz nonexistent:
Quickly checks if a command is installed on the system. If whereis returns only the command name with no paths, the command is not found in standard locations. Useful in scripts to verify prerequisites before running operations.
Script Validation: Check for required commands before execution