Introduction
The Linux whereis
command locates the binary, source, and manual page files for a command. The whereis
utility provides a concise way to gather information about a target command and allows users to analyze the file structure of a Linux system
This article will teach you about Linux whereis
command through its use case examples.
Prerequisites
- Linux system (this tutorial uses Ubuntu 22.04).
- Access to the terminal.
Linux whereis Command Syntax
The whereis
command syntax is:
whereis [options] [command_name]
Running the command without any options or [command_name]
in Ubuntu results in an error message:
whereis
However, in other Linux distributions, doing the same could produce general output about commonly used commands. The output depends on the system.
Linux whereis Command Options
The options customize whereis
, producing specifically tailored output. The common arguments are:
Option | Description |
---|---|
-b | Prints only executables. |
-B | Prints executable within a specific directory. |
-m | Displays only manual pages. |
-M | Displays manual pages but within a particular directory. |
-s | Shows only source files. |
-S | Shows only source files but within a specified directory. |
-u | Searches for unusual entries. |
-l | Lists specified file's components. |
-f | Terminates the last component in the file path. It is always used with -B , -M , or -S . |
-h | Displays help information. |
-V | Prints version info. |
whereis Command in Linux: Examples
The whereis
command works with different options and has many use-case examples. The following texts elaborates on the most important examples.
Example 1: Find Command Location
To locate a command, run whereis
with the target command name. For instance, find the ls command location with the following:
whereis ls
The output indicates where the ls
executable file is and shows the man page location.
Example 2: Locate Multiple Commands
To find more than one command, type whereis
and each [command_name]
separated by a space. For instance, find the locations for ls
, cat, and whoami with:
whereis ls cat whoami
Example 3: Identify whereis Target Locations
By default, whereis
looks for a command's files in pre-defined paths and directories specified in the environment variables.
To identify the searched directories, use the -l
option.
For example:
whereis -l
This output shows the specific directories that whereis
examines while searching command-related files.
Example 4: Locate the Command Binary
To find only the command's executable (binary) file, run whereis
with -b
:
whereis -b [command_name]
For example, find the ls
binary file:
whereis -b ls
Unlike the previous example, the output prints only the path to the executable and excludes the manual page.
Example 5: Find Binary in a Specific Location
To pinpoint command executables exclusively within particular directories, use the -B
and -f
options. The -B
argument designates a specific directory, while the -f
option, always paired with -B
, specifies that the subsequent term in the command is the target command.
The syntax is:
whereis -b -B [directory_name] -f [command_name]
For example, locate ls
binaries within the /bin directory with the following:
whereis -b -B /bin -f ls
Example 6: Locate the Man Page
If the goal is only to show the manual page location, run the command with -m
.
whereis -m [command_name]
For instance:
whereis -m ls
The output shows only the ls
manual page location.
Example 7: Find Unusual Entries
To search for unusual entries that deviate from the standard or expected location, use the -u
argument. For example, find all unusual entries in the current directory with:
whereis -s *
Conclusion
After reading this article, you should know how to use the whereis
command and its options by following use-case examples.
Next, read about other important commands in this Linux commands cheat sheet.