The whereis command searches a predefined set of standard system paths to locate the binary, source, and manual page files for a command. Because it targets a fixed directory list rather than crawling the entire filesystem, lookups complete almost instantly — useful for auditing what is installed, troubleshooting PATH conflicts, verifying documentation is present, and writing scripts that rely on absolute binary paths.
Understand the whereis Command
Common whereis Use Cases
Understanding the location of command files is not just a matter of convenience. It is often essential for:
- Troubleshooting: Knowing where a command’s binary or source files are can help diagnose issues related to that command.
- Scripting: When writing scripts, especially those meant to run across different systems, it’s crucial to reference the correct command path.
- System Administration: Admins often need to confirm whether a utility is installed and which copy lives on the system.
whereis vs which vs type vs locate
Four commands locate programs or files on a Linux system, each with a different scope. Understanding when to use each prevents confusion when their results differ.
| Command | What It Finds | Search Scope | Best Used For |
|---|---|---|---|
whereis | Binary, source, and man pages | Predefined standard system paths | Auditing what is installed and where docs live |
which | First binary match in $PATH | Your current $PATH only | Checking which binary the shell runs |
type | Shell interpretation (alias, builtin, function, or file) | Shell environment | Diagnosing aliases and shell builtins |
locate | Files matching a name pattern (from a pre-built database) | Entire filesystem (indexed by updatedb) | Finding any file by name when the database is current |
If two versions of a tool are installed, whereis python3 may list both copies, while which python3 shows only the one your $PATH resolves first. Use whereis for a broad audit; see which command in Linux for checking exactly what the shell invokes.
whereis Command Syntax
The fundamental structure of the whereis command is:
whereis [options] command_name
If you supply custom search paths with -B, -S, or -M, terminate the path list with -f before the command name to avoid errors.
For instance, to locate the binary, source, and documentation files for the ls command:
whereis ls
This can return output like the following on a minimal system:
ls: /usr/bin/ls
If you install documentation files, whereis includes man or info paths in the same line.
On Alpine Linux and other distributions that keep separate
/binand/sbinpaths,whereis lsreturnsls: /bin/lsinstead ofls: /usr/bin/ls. Modern distributions merge these into/usr/bin, so both are valid depending on the system.
whereis Command Quick Reference
The table below summarizes the most-used whereis flags and their effect on search scope.
| Flag | Description | Example |
|---|---|---|
-b | Binaries only | whereis -b ls |
-m | Manual and info pages only | whereis -m grep |
-s | Source files only | whereis -s ls |
-l | List all effective search paths | whereis -l |
-g | Glob pattern search (util-linux 2.38+) | whereis -g 'ls*' |
-u | Show commands with unusual or missing entries | whereis -u ls grep |
-B <dirs> -f | Restrict binary search to specific directories | whereis -b -B /usr/bin -f ls |
-M <dirs> -f | Restrict manual search to specific directories | whereis -m -M /usr/share/info -f grep |
Install the whereis Command
Most distributions ship whereis as part of util-linux. Check if it is already available:
whereis --version
whereis from util-linux 2.39.3
If the command returns no output, minimal containers or stripped images may have omitted it. Use the install commands below for your distribution.
Ubuntu and Debian-based distributions
First, refresh the APT index, then install util-linux if your system does not include it.
sudo apt update
sudo apt install util-linux
Running apt update refreshes the package index so you install the latest available release.
Fedora
On Fedora, install util-linux with DNF5.
sudo dnf install util-linux
RHEL, Rocky Linux, AlmaLinux, and CentOS Stream
On RHEL and compatible distributions, install util-linux with DNF.
sudo dnf install util-linux
Arch Linux and Manjaro
Use Pacman to install util-linux on Arch-based systems.
sudo pacman -S util-linux
openSUSE
Use Zypper to install util-linux on openSUSE.
sudo zypper install util-linux
Alpine Linux
Alpine ships the whereis binary in util-linux-misc.
sudo apk add util-linux-misc
Gentoo
On Gentoo, install sys-apps/util-linux with Portage.
sudo emerge --ask sys-apps/util-linux
Void Linux
On Void, install util-linux with XBPS.
sudo xbps-install -S util-linux
View all available options:
whereis --help
Usage: whereis [options] [-BMS <dir>... -f] <name> Locate the binary, source, and manual-page files for a command. Options: -b search only for binaries -B <dirs> define binaries lookup path -m search only for manuals and infos -M <dirs> define man and info lookup path -s search only for sources -S <dirs> define sources lookup path -f terminate <dirs> argument list -u search for unusual entries -g interpret name as glob (pathnames pattern) -l output effective lookup paths -h, --help display this help -V, --version display version For more details see whereis(1).
Practical Examples of whereis
Locate System Utilities
To locate the binary and associated files for the passwd utility:
whereis passwd
The output shows the binary alongside the /etc/passwd account database:
passwd: /usr/bin/passwd /etc/passwd
The /etc/passwd file is the local user database, not a command configuration file. whereis includes it because it matches the name in a standard system path.
Locate Text Search Tools
To locate grep and confirm its documentation is installed (see grep command in Linux):
whereis grep
The output includes the binary and the info documentation file:
grep: /usr/bin/grep /usr/share/info/grep.info.gz
Info files are part of the documentation set that whereis reports alongside binaries.
Locate Stream Editors
To confirm the binary and documentation locations for sed (see sed command in Linux):
whereis sed
This returns the binary and info file paths:
sed: /usr/bin/sed /usr/share/info/sed.info.gz
On systems that include man pages, you may also see man paths alongside the info file.
Locate Shells and Interpreters
Scripts often invoke shells like bash directly. To locate bash on the system:
whereis bash
The output shows the binary path:
bash: /usr/bin/bash
Use this path in scripts that need an explicit shebang line (#!/usr/bin/bash) or full binary path for automation.
Locate File Management Commands
To confirm the path for mkdir (see mkdir command in Linux):
whereis mkdir
This returns the exact binary path:
mkdir: /usr/bin/mkdir
Useful when troubleshooting PATH issues or verifying which binary the shell resolves.
Search Only Binaries
The -b flag restricts the search to binaries only, skipping man pages and source files:
whereis -b ls
The output shows only the binary location:
ls: /usr/bin/ls
In this output, the -b option directs whereis to display only the binary location. On modern distributions, /bin often points to /usr/bin, so you may see /usr/bin/ls even when searching for binaries only.
Search Only Source Files
The -s flag restricts results to source file locations:
whereis -s ls
On most systems, this returns an empty result because most distributions do not install source files by default:
ls:
If you install source packages for a command, -s will list those locations.
Search Manual and Info Pages
Manual pages and info pages are the built-in documentation for Linux commands. They provide detailed descriptions, options, and usage examples, and the -m option locates them.
whereis -m grep
grep: /usr/share/info/grep.info.gz
Minimal images often strip man pages; on those systems, the info file is the only documentation available.
Locate Multiple Commands at Once
To look up multiple commands in a single call, pass all names as arguments:
whereis ls pwd
The output shows all found entries for each command on separate lines:
ls: /usr/bin/ls pwd: /usr/bin/pwd
Combine Search Type Flags
Combine type flags to search only specific file categories. The -ms combination restricts results to manual pages and source files, skipping the binary entirely. Use it to confirm whether documentation or source packages are installed without the binary path appearing in the output.
whereis -ms ls
Because most distributions do not install source packages by default, this typically returns an empty result on standard systems:
ls:
Use -ms when checking whether documentation or source packages are installed, without the binary path appearing in the output.
Advanced whereis Techniques
List whereis Search Paths
The -l option prints the directories whereis searches for binaries, sources, and documentation.
whereis -l
The output lists all directories searched, prefixed by type:
bin: /usr/bin bin: /usr/sbin bin: /usr/lib/x86_64-linux-gnu bin: /usr/lib bin: /usr/lib64 bin: /etc bin: /usr/local/bin bin: /usr/local/sbin bin: /usr/share man: /usr/share/man/man1 man: /usr/share/man/man8 man: /usr/share/info ...
If a command you search for is not found, its files likely live in a path not listed here. Use -B, -M, or -S with -f to extend the search to those directories.
Find Commands with Unusual Entries
The -u flag outputs only the commands from a list whose entries span more than one search category — those with both a binary and documentation files, for example:
whereis -u ls grep sed gzip
Only commands with unusual patterns appear in the output:
grep: /usr/bin/grep /usr/share/info/grep.info.gz sed: /usr/bin/sed /usr/share/info/sed.info.gz gzip: /usr/bin/gzip /usr/share/info/gzip.info.gz
ls is omitted because it has only a binary with no documentation on this system. grep, sed, and gzip each have both a binary and an info file, spanning two search categories. Use -u to batch-audit a set of tools and identify which ones have documentation or are missing it.
Use Glob Patterns with -g
The -g option, available on util-linux 2.38 and later, interprets the name argument as a glob pattern, matching all commands whose names fit the pattern:
whereis -g 'ls*'
On a standard system, the output includes all installed commands matching the pattern:
ls*: /usr/bin/lsblk /usr/bin/lsipc /usr/bin/lscpu /usr/bin/lslocks /usr/bin/lsmem /usr/bin/lsns /usr/bin/lslogins /usr/bin/lsattr /usr/bin/ls /usr/lib/lsb /etc/lsb-release
Ubuntu 22.04 lacks the
-goption, andwhereis -g 'ls*'returnswhereis: bad usage. In that case, list command names explicitly, for examplewhereis ls lsblk lscpu.
Limit the Search Path
whereis searches in standard directories by default, but you can limit the search to specific paths. The -B, -S, and -M options define custom paths, and -f ends the list before the command name.
whereis -b -B /bin -f ls
This command confines the search to /bin and shows only binaries:
ls: /usr/bin/ls
On modern distributions, /bin often points to /usr/bin, so the binary still resolves there.
Search a Specific Documentation Path
You can point the documentation search to a specific directory with -M. For example, search the info directory for grep documentation:
whereis -m -M /usr/share/info -f grep
grep: /usr/share/info/grep.info.gz
Use -M to direct documentation lookups to a specific directory when custom info paths are installed outside the defaults.
Search Multiple Binary Paths
whereis does not exclude directories directly, so define the paths you want to search. You can provide multiple directories after -B and end the list with -f:
whereis -b -B /usr/bin /usr/local/bin -f grep
grep: /usr/bin/grep
Add additional directories after -B as needed to cover custom binary locations.
Troubleshoot Common whereis Errors
Missing -f Option Error
If you see an error about a missing -f option, you did not separate the command name from the path list:
whereis -b -B /bin ls
whereis: option -f is missing
Add -f before the command name and rerun the lookup to confirm the result:
whereis -b -B /bin -f ls
ls: /usr/bin/ls
Empty Result After Lookup
If a lookup returns only a name and a colon, the system is missing the binary or has stripped the documentation:
whereis -m ls
ls:
Confirm the command exists in your PATH before troubleshooting further:
command -v ls
/usr/bin/ls
Conclusion
The whereis command searches a predefined set of standard system paths and returns all matching binaries, man pages, and source files in one call. Use -b, -m, and -s independently to narrow results, or combine them with -B, -M, -S, and -f to restrict the search to specific directories. For a full filesystem scan, reach for find -exec in Linux; for checking which binary the shell actually runs, use which in Linux.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed:
<code>command</code>command<strong>bold</strong><em>italic</em><a href="URL">link</a><blockquote>quote</blockquote>