Linux command whereis
helps locate where a specific file resides on the system, including related binary files (executable files), source files, and manual pages. In this post, we will explore the basic usage of the whereis
command and several useful options.
Table of Contents
What Is the Linux Command whereis?
The whereis
command is primarily used to locate the executable file, source code, and manual (man) pages for a specific command. It helps to quickly find the file path of a program installed on the system, which is particularly useful when you need to verify where a program is installed. For example, to find the location of the ls
command, you can enter whereis ls
.
Basic Usage
whereis [option] [filename to search]
ShellScriptIn the above format, the [option]
can be omitted, and the [filename to search]
is where you input the command or file name you are looking for.
Example
whereis ls
ShellScriptWhen you run this command, it will output the paths for the binary file, source file, and manual page related to the ls
command. As seen below, this means that the executable file for the ls
command is located at /bin/ls
and the related manual page is at /usr/share/man/man1/ls.1.gz
.
Key Options for the whereis Command
The whereis
command offers a variety of options to help users search for files in the way they need. Let’s take a look at some of the key options.
-b: Search Only for Binary Files
The -b
option searches only for binary files, excluding source files and manual pages. For example, the following command will output only the location of the ls
command’s executable file:
whereis -b ls
ShellScriptIn the figure below, you can see that only the path for the executable file is displayed.
-m: Search Only for Manual Files
The -m
option searches only for manual files. For example, the following command will output only the location of the ls
command’s manual file:
whereis -m ls
ShellScriptIn the figure below, you can see that only the path for the manual file is displayed.
-s: Search Only for Source Files
The -s
option searches only for source files. For example, the following command will output only the location of the ls
command’s source file:
whereis -s ls
ShellScriptIf the source file cannot be found, the output will simply show the command name.
-u: Output Only When a File Is Missing
The -u
option outputs results only if any of the binary, source, or manual files are missing. For example, if a program lacks a manual, this option will quickly let you know.
whereis -u ls
ShellScript-B, -M, -S: Specify Search Paths
The whereis
command searches in predefined paths by default. However, if you want to search for files only in specific directories, you can use the -B
, -M
, or -S
options to specify search paths.
-B
: Specify the path to search for binary files-M
: Specify the path to search for manual files-S
: Specify the path to search for source files
For example, if you only want to search for the binary file of the zsh
command in the /usr/bin
directory, you can enter:
whereis -B /usr/bin -b zsh
ShellScriptIn the figure below, you can see that there are multiple paths for zsh
. If you specify the binary path as /usr/bin
, it will search for the binary only in that path.
Tips for Using the whereis Command
Solving System Issues
The whereis
command is useful when a program is not located in the expected path. It can help you quickly verify if a program is installed or diagnose issues when a program is installed in the wrong path.
Verifying Missing Manual Pages
In Linux, you can easily check the usage of commands via their manual pages. By using the whereis -m
option, you can verify if a command’s manual page is missing. If it is absent, you may need to install it separately.
Checking Multiple File Locations
If you want to find the location of multiple files or commands at once, you can list the file names separated by spaces.
whereis ls cp mv
ShellScriptThis command will output the file locations for ls
, cp
, and mv
all at once, as shown below.
Usage Precautions
- Be Aware of Symbolic Links: The
whereis
command does not follow symbolic links (links that point to other files). Therefore, it may return the location of the link rather than the actual file. - Path and Environment Variables: The
whereis
command searches based on paths defined in thePATH
environment variable. If a program is installed in a directory not included inPATH
, thewhereis
command may not be able to locate it. - Use Exact File Names: Be sure to input the exact file name when using
whereis
. Otherwise, you may get unexpected results.
Summary
Searching for files in Linux is an essential task, and the Linux command whereis
is a valuable tool that quickly and accurately locates files. By leveraging various options, you can search for only the files you need or specify directories to search in. This tool is particularly helpful for verifying if programs are installed correctly or if the necessary manual pages are available.
References
Related Posts