Home / Alt manpages / whereis(1)

  • whereis(1)
  • User command
  • linux

Find a Command's Binary, Manual and Source with whereis

You will finish with a quick way to see where Linux finds a command's executable, manual page and source, plus a controlled search when the default result is too broad. The examples use whereis from util-linux 2.42.4, installed here. Allow about ten minutes. You need a shell and a command name to investigate. Every command in this guide is read-only; none needs sudo.

1. Run the default lookup

Start with the command name, not its full path:

$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

The output is labelled with the name you supplied, followed by the matching paths. This result has a binary and a manual page, but no source file. A command can have several matches, and no match is not necessarily an error in your shell or package manager.

whereis strips leading path components before searching, so this also looks for the basename ls:

$ whereis /usr/bin/ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

Checkpoint: if you only want to know whether a shell will execute a program, use the shell's command -v as a separate check. whereis searches more than the current command lookup path and is not a replacement for shell resolution.

2. Restrict the kind of file

The short options make the result easier to read when you know what you are checking:

$ whereis -b ls
ls: /usr/bin/ls
$ whereis -m whereis
whereis: /usr/share/man/man1/whereis.1.gz

Use -b for binaries, -m for manuals and Info documentation, and -s for source. These restrictions are cumulative for the names that follow. A later restriction starts a new mask, which makes option order significant:

$ whereis -bm ls tr -m gcc

The first two names are searched for binaries and manuals. gcc is searched for manuals only. Read a command like this from left to right; do not assume that one set of options applies to every name on the line.

3. See the paths that are actually searched

When a result surprises you, list the effective lookup paths:

$ whereis -l
bin: /usr/bin
bin: /usr/sbin
bin: /usr/lib/x86_64-linux-gnu
bin: /usr/lib
bin: /usr/lib32
bin: /usr/lib64
bin: /etc
bin: /usr/games

The complete output can be longer than this excerpt. By default, whereis combines hard-coded patterns with locations derived from $PATH and $MANPATH. An unusual environment can therefore change the answer. Compare whereis -l with printf '%s\n' "$PATH" and printf '%s\n' "$MANPATH" before debugging a package.

Do not confuse a path being searched with a file being present there. -l reports lookup paths; it does not prove that a particular command exists.

4. Limit a search to known directories

Use -B, -M or -S when you need a bounded check. Each option takes a whitespace-separated directory list. -f marks the end of that list and the start of the command names:

$ whereis -b -B /usr/bin -f ls
ls: /usr/bin/ls
$ whereis -m -M /usr/share/man/man1 -f whereis
whereis: /usr/share/man/man1/whereis.1.gz

-B limits binary directories, -M limits manual and Info directories, and -S limits source directories. The options reset the corresponding search path for names that follow. Forgetting -f is a common distraction trap: a directory-looking argument can be consumed as part of the directory list, leaving no name to search.

These options do not install, move or delete anything. They only change this invocation's search rules. Use an absolute directory you have already inspected, and do not treat an empty result as evidence that the package is absent everywhere.

5. Search names with a glob

-g interprets the next names as filename patterns. Quote the pattern so the shell does not expand it before whereis receives it:

$ whereis -g 'find*'
find*: /usr/bin/find /usr/bin/find-all-symbols-20 /usr/bin/findmnt /usr/sbin/findfs /usr/share/man/man1/find.1.gz

The real output may contain additional matches on another machine. Patterns are compared with basenames, not complete paths, so putting a directory in the pattern does not narrow the search. The quotes are essential. Without them, the current directory's matching filenames are expanded by the shell first, changing the query before whereis runs.

6. Find unusual or incomplete entries

-u reports command names that do not have exactly one entry of each explicitly requested type. For example, this asks for names whose manual entries are missing or duplicated in one directory:

$ cd /usr/share/man/man1
$ whereis -m -u -M /usr/share/man/man1 -f whereis
$ printf 'status=%s\n' "$?"
status=0

No command name was printed here because the requested manual search produced one entry. With a wildcard, quote nothing only when you deliberately want the shell to expand the current directory, as in the documented audit pattern. Otherwise use -g and a quoted pattern so that whereis controls the matching.

The cd above changes only the current shell. If you are working interactively and want to return, run cd - or start a new shell. There is no system state to undo.

7. Check the installed implementation

Use the version option when behaviour matters in a script or support note:

$ whereis --version
whereis from util-linux 2.42.4

Option availability and path details belong to the installed util-linux version. The local manual documents -b, -m, -s, -u, -B, -M, -S, -f, -l, -g, -h and -V. For a machine with different output, run whereis --help and its local manual before copying a command into automation.

Done means

  • You can distinguish binary, manual and source results with -b, -m and -s.
  • You have checked lookup paths with whereis -l before blaming a missing package.
  • Any bounded -B, -M or -S search ends its directory list with -f.
  • Any -g pattern is quoted, so the shell does not rewrite it first.
  • You have recorded the local util-linux version when the result must be reproducible.