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.
- Linux system (this tutorial uses Ubuntu 22.04).
- Access to the terminal.
Linux whereis Command Syntax
whereis command syntax is:
whereis [options] [command_name]
Running the command without any options or
[command_name] in Ubuntu results in an error message:
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:
|Prints only executables.
|Prints executable within a specific directory.
|Displays only manual pages.
|Displays manual pages but within a particular directory.
|Shows only source files.
|Shows only source files but within a specified directory.
|Searches for unusual entries.
|Lists specified file's components.
|Terminates the last component in the file path. It is always used with
|Displays help information.
|Prints version info.
whereis Command in Linux: Examples
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:
The output indicates where the
ls executable file is and shows the man page location.
Example 2: Locate Multiple Commands
whereis ls cat whoami
Example 3: Identify whereis Target Locations
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
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 -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
-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
whereis -m [command_name]
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 *
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.