opscape

Finding things

whereis

Locate the binary, source and manual page files for a command in the standard system directories.

whereis [-bms] [-BMS DIR... -f] NAME...

7 of 7 examples run in Debian 13.7 on 2026-10-31 · util-linux 2.41.5-0+deb13u1 · manual: whereis(1)

whereis looks for files belonging to a command name in a fixed list of standard places: binaries in directories like /usr/bin and /usr/sbin, manual pages under /usr/share/man, and sources under /usr/src. It prints every match on one line, starting with the name.

Unlike which, it does not follow your $PATH order and does not tell you which file would run; it answers "where are this program's files installed?". That includes related directories such as /etc/python3 or /usr/lib/python3. Use which or type for "what runs when I type this", and whereis when you are hunting for a program's man page or a binary outside your PATH, such as one in /usr/sbin when you are not root.

Examples

Find a command's files

whereis bash
explain
output
bash: /usr/bin/bash

The output starts with the name and a colon, followed by every file found. The sandbox has no manual pages installed, so only the binary appears; on a full system you would also see something like /usr/share/man/man1/bash.1.gz.

Show only binaries with -b

whereis -b python3 sshd ip
explain
output
python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3
sshd: /usr/sbin/sshd
ip: /usr/bin/ip /usr/sbin/ip

-b restricts the search to whereis's binary list, which on Debian also includes /etc, /usr/lib and /usr/share, so Python's directories still show. sshd lives in /usr/sbin, which an unprivileged user's PATH often lacks; whereis finds it anyway because it searches its own list of directories. ip turns up in both /usr/bin and /usr/sbin.

Look for manual pages with -m

whereis -m ls
explain
output
ls:

-m searches only for manual pages. None are installed in this minimal container, so the result is the bare name and a colon, and the exit status is still 0: whereis does not signal "not found" through its exit status.

Unknown names print an empty entry

whereis nosuchcmd; echo "exit status: $?"
explain
output
nosuchcmd:
exit status: 0

There is no error and the status is 0. To test for a missing command in a script, check whether the output has anything after the colon, or use command -v instead.

Search specific directories with -B and -f

Setup run before this example
mkdir -p /home/dev/demo/tools
cp scripts/greet.sh tools/greet
whereis -b -B "$PWD/tools" /usr/bin -f greet python3
explain
output
greet: /home/dev/demo/tools/greet
python3: /usr/bin/python3

-B replaces the binary search path with the directories that follow, and -f marks the end of that list and the start of the names. The local tools/greet script is found even though it is in no standard place.

Show the directories whereis searches

whereis -l | head -8
explain
output
bin: /usr/bin
bin: /usr/sbin
bin: /usr/lib/x86_64-linux-gnu
bin: /usr/lib
bin: /usr/lib64
bin: /etc
bin: /usr/games
bin: /usr/local/bin

-l prints the search path, each line tagged bin, man or src. Piped to head to keep it short; the full list depends on the system.

Common pitfalls

  • whereis does not use $PATH order, so its first result is not necessarily what runs. Use which or type for that.

  • It always exits 0 for names it cannot find, so if whereis foo is always true.

  • It matches by name only. A file in a standard directory with the same name as the command shows up even if it is unrelated.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • Linux whereis comes from util-linux. macOS and FreeBSD have their own whereis with different options and behavior (macOS's searches for the program in the standard binary directories and prints just its path), so do not rely on its output format across systems.

Options worth knowing

A selection, described in our own words. For the full list, see whereis(1) or whereis --help.

OptionWhat it does
-bSearch only for binaries.
-mSearch only for manual pages.
-sSearch only for sources.
-uShow only names with an unusual number of entries.
-B DIRSearch for binaries only in the listed directories (end the list with -f).
-M DIRSearch for manual pages only in the listed directories (end the list with -f).
-S DIRSearch for sources only in the listed directories (end the list with -f).
-fEnd a -B, -M or -S directory list; the names follow.
-lPrint the directories that are searched.

Related