Linux whereis Command: Find Binary, Source, and Manual Files
Learn how to use Linux whereis to locate program binaries, source files, and manual pages, filter results, customize search directories, and compare it with which, type, find, and locate.
The Linux whereis command finds standard files associated with a program. It can report the program's executable binary, source code files, and manual-page files.
Unlike find, whereis does not recursively inspect the entire filesystem. It searches a restricted set of directories known or configured for binaries, source code, and manuals.
What the whereis Command Finds
A binary is an executable program file. Common binary directories include /bin, /usr/bin, and /usr/sbin.
Source code consists of human-readable files used to build a program. Source files are often not installed on ordinary end-user systems.
A manual page is system documentation read with man. Manual pages are commonly stored below directories such as /usr/share/man. They are frequently compressed with gzip, so a file may end in .gz.
For a named program, whereis can search for all three categories. Its search is limited to standard or configured directories; it is not a general-purpose arbitrary-file search.
Basic Syntax
whereis program_name
Enter the program name without its full path. For example:
whereis ls
Output begins with a colon-separated label containing the name you supplied, followed by zero or more matching paths. A typical result may resemble:
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
The exact paths depend on the Linux distribution, installed packages, and system layout.
Reading whereis Output
- A path such as
/bin/ls,/usr/bin/ls, or/usr/sbin/exampleis usually an executable binary result. - A path below
/usr/share/man, especially one ending in.gz, is commonly a compressed manual page. - Several paths can appear when multiple binaries, manual pages, or other relevant files match.
- If the output contains only the name, or is otherwise nearly empty, no matching file was found in the directories searched by
whereis.
Find a Command and Its Manual Page
netstat is a useful networking example because an installation may provide both an executable and a manual page:
whereis netstat
Possible output could include an executable such as /usr/bin/netstat and a manual page such as /usr/share/man/man8/netstat.8.gz. Do not assume these exact paths: netstat may be absent, and many current systems prefer the ss utility supplied by the iproute2 package.
To inspect a common system command, run:
whereis ls
This commonly shows the binary and one or more manual-page paths.
Selective Search Options
Use category options when you need only one kind of result:
Search for Only a Binary
whereis -b netstat
The -b option suppresses manual-page and source results. It is useful when you want to investigate where an executable is installed.
Search for Only a Manual Page
whereis -m netstat
The -m option searches only for manual-page files. The result may include compressed files such as netstat.8.gz.
Search for Only Source Files
whereis -s netstat
The -s option searches only for source files. An empty result is normal when the program's source package has not been installed.
Control the Directories Searched
The -B, -M, and -S options replace the default directory list for one category:
-Bsupplies directories for binary searches.-Msupplies directories for manual-page searches.-Ssupplies directories for source searches.
The directory list must be followed by -f. This marker tells whereis that the custom directory list has ended and the program names begin.
whereis -B /usr/local/bin /opt/tools/bin -f customtool
This searches /usr/local/bin and /opt/tools/bin for a binary named customtool.
whereis -M /usr/local/man -f customtool
whereis -S /usr/local/src -f customtool
The first command limits the manual-page search to /usr/local/man. The second limits the source search to /usr/local/src.
Investigate Unusual Match Counts with -u
The -u option reports commands that have an unusual number of matches in the categories selected for the search. It is useful for investigating missing or unexpected binaries, source files, or manual pages.
whereis -u -b -m netstat
Here, -u is applied while binary and manual-page categories are selected. It can help highlight a command with a missing binary or manual page, or with an unexpected number of matches.
-u is not a general filesystem integrity checker. It only evaluates the relevant whereis categories and its configured search locations.
whereis Search Behavior and Limitations
whereisdoes not perform a full recursive filesystem search.- Its results are limited to directories known or configured for binaries, source files, and manuals.
- It may not find user-created scripts stored in a home directory or another nonstandard location.
- It is not the best choice for locating an arbitrary file anywhere on the system.
- It does not necessarily identify the executable selected by the current shell's
PATH. - It generally does not locate runtime configuration files, such as files under
/etc, unless a file happens to match a searched category and location.
PATH is the shell environment variable containing directories searched when you enter a command without a path. A program can therefore appear in whereis output without being the version that your shell runs.
Compare Related Lookup Commands
For more detail about displaying the executable selected by a shell, see show the full path of shell commands. For shell behavior, the Bash guide provides useful background.
whereis Compared with which
Use which when your question is, “Which executable will be found through the current PATH?” Use whereis when you want a broader view of standard binary, source, and manual locations.
whereis Compared with type
type can reveal that a name is an alias, shell builtin, function, keyword, or executable. whereis is focused on files and does not explain shell aliases or functions.
whereis python3; command -v python3; type python3
These commands may produce different information. For example, whereis can list several standard files, while command -v reports the command path selected by the current shell. type also identifies non-file shell commands.
whereis Compared with locate and find
Use locate for a broad filename lookup based on a database. Its results can be stale or absent from the database. Use find for a live recursive search with conditions such as name, type, owner, or permissions. Neither tool is limited to the standard program categories used by whereis.
Use man to Read Documentation
whereis identifies a manual-page file; man opens and formats the documentation for reading:
whereis -m ls
man ls
You normally pass the command name to man rather than the compressed file path. The manual system handles compression automatically.
Troubleshooting whereis Results
Only the Command Name Is Printed
If whereis returns only the name and no paths, possible causes include:
- The program is not installed.
- The program is installed outside the directories searched by
whereis. - The name entered does not match the installed file name.
Check shell resolution first:
command -v program_name
If the shell can run the program but whereis cannot find it, use find for a broader search or inspect the package installation. Also verify the program or package name.
A Manual Page Is Found but No Executable
Documentation may be installed separately from the executable. The executable may also be outside standard binary directories, or the manual page may belong to an optional package.
command -v program_name
whereis -b program_name
Inspect installed packages with your distribution's package manager when necessary.
An Executable Is Found but No Manual Page
Some packages omit manual pages, especially minimal installations. Documentation may be supplied separately or in another format.
- Try
program_name --help. - Check for an optional documentation package.
- Consult the distribution's package documentation.
whereis Shows a Different Path from the Running Command
This can happen when PATH prioritizes another installation, multiple versions exist, or an alias, function, wrapper script, or shell builtin has the same name.
type program_name
command -v program_name
printf '%s\n' "$PATH"
Review the directory order and use the intended executable's full path when required.
Custom Search Options Give Unexpected Results
- Ensure the custom directory list ends with
-f. - Use
-Bfor binaries,-Mfor manual pages, and-Sfor source files. - Confirm that the target directories contain the expected file category.
You can inspect a custom directory with ls or use find when a more detailed search is needed.
Exam-Relevant Notes
whereis program_namesearches for standard binary, source, and manual-page files.-b,-m, and-sselect binaries, manuals, and source files respectively.-B,-M, and-Sprovide custom category directories;-fends those directory lists.-ureports unusual match counts for selected categories; it is not a full integrity check.whereisis not equivalent towhich: it does not simply report the executable selected throughPATH.- Use
typefor aliases, builtins, functions, and other shell resolution details; usefindorlocatefor broader file discovery.
Quick Practice
- Run
whereis netstatand identify any binary and manual-page paths. - Run
whereis -b netstatand compare the categories in the output. - Run
whereis -m netstatand look for a compressed manual page. - Run
whereis -B /usr/local/bin /opt/tools/bin -f customtoolto practice the custom binary directory syntax. - Run
whereis python3; command -v python3; type python3and explain why the results may differ. - Run
whereis -m ls; man lsto separate documentation discovery from documentation reading.