Introduction
The whereis command is a simple yet powerful tool available in most Linux distributions that allows you to quickly locate binary files, source code, and manual (man) pages associated with a given program. Unlike other utilities such as find or locate, whereis searches a predefined set of system directories, making it very fast and suitable for everyday administration and development tasks. In this article we will see what whereis is, how its syntax works, what options it offers, and some practical examples to get the most out of it.
What is the whereis command?
whereis is part of the util-linux package and is responsible for searching the standard paths where the system stores executables (/bin, /sbin, /usr/bin, /usr/sbin, etc.), libraries, source code, and manuals. Its main goal is to provide an immediate answer when we need to know where a command is installed or where to find its documentation, without having to scan the entire filesystem. This makes it a lightweight alternative to find when an exhaustive search is not required.
Basic syntax
The syntax of whereis is very simple:
whereis [options] command_name
If no options are specified, whereis will by default show the location of the binary, the source code (if it exists), and the manual page. For example:
whereis ls
will produce something like:
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
Most used options
- -b: Search only binaries.
- -m: Search only manual pages.
- -s: Search only source code.
- -u: Search for entries that do not have one of the requested types (useful for finding anomalies).
- -B: Change the binary search path.
- -M: Change the manual search path.
- -S: Change the source code search path.
These options can be combined as needed. For example, whereis -b gcc will show only the location of the gcc binary.
Practical examples
- Check installation of a program:
whereis nginxmay return/usr/sbin/nginxand its manual, confirming that the server is present. - Locate only the manual:
whereis -m python3will show the path to the python3 manual page, useful when you want to quickly consult the documentation without opening the help terminal. - Search for source code:
whereis -s bashmay return/usr/src/bash-5.1/if the sources are installed. - Detect missing files:
whereis -u commandcan help identify if any of the three components (binary, source, manual) are missing in a partial installation.
Limitations and alternatives
Although whereis is fast, it has certain limitations. Its search is restricted to predefined directories; if a binary is located in a non-standard location (for example, in /opt or in the user’s home directory), whereis will not find it. In those cases you need to resort to find or locate, which scan the entire filesystem or a periodically updated database. Moreover, whereis does not recursively follow symbolic links by default, although it does follow links that appear in its search paths.
Conclusion
The whereis command is an essential tool for any Linux user or administrator who needs to quickly locate binaries, manuals, and source code. Its simple syntax and filtering options make it ideal for quick checks and administration scripts. Knowing how it works and its limits allows you to combine it effectively with other utilities like find and locate, ensuring you always have the correct information at hand.
This post is also available in ESPAÑOL.