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...
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
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.
See related directories too
whereis python3
python3: /usr/bin/python3 /usr/lib/python3 /etc/python3 /usr/share/python3
whereis also reports directories named after the command in its search paths, here the library and configuration directories of Python.
Show only binaries with -b
whereis -b python3 sshd ip
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
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: $?"
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/greetwhereis -b -B "$PWD/tools" /usr/bin -f greet python3
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
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
$PATHorder, so its first result is not necessarily what runs. Usewhichortypefor that.It always exits 0 for names it cannot find, so
if whereis foois 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
whereiscomes from util-linux. macOS and FreeBSD have their ownwhereiswith 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.
| Option | What it does |
|---|---|
-b | Search only for binaries. |
-m | Search only for manual pages. |
-s | Search only for sources. |
-u | Show only names with an unusual number of entries. |
-B DIR | Search for binaries only in the listed directories (end the list with -f). |
-M DIR | Search for manual pages only in the listed directories (end the list with -f). |
-S DIR | Search for sources only in the listed directories (end the list with -f). |
-f | End a -B, -M or -S directory list; the names follow. |
-l | Print the directories that are searched. |
Related
whichShow which executable file in PATH would run for a command name.typeShow how the shell would interpret a name, as an alias, keyword, function, builtin or file on PATH.commandRun a command while skipping functions and aliases of the same name, or check whether a command exists with -v.findWalk a directory tree and print, or act on, every file that matches a set of tests.- Environment variablesHow export passes variables to child processes, the one-command NAME=value prefix, loading .env files, and why a child cannot change its parent.