The “whereis” command in Linux is a powerful tool that helps identify the location of a command or file on the system. It searches through defined directories and databases to find the binary, source, and manual page files associated with the specified command or file. It is typically used to quickly locate the location of a command or file without having to search through the entire file system manually.
This article will explore the usage and options of the whereis command in Linux and how it can be used to find files and commands on a Linux system.
- Use whereis Command – Syntax and Basics
- Displaying the List of All Directories
- Locating any Directory Path
- Location of the Manual of Any Command
- Showing Only Binary Files
How to Use the whereis Command?
Each Linux Command has a set of options and a basic syntax. The syntax and primary options of the whereis command can be viewed as follows:
$ whereis --help
In the above image, you can see the syntax of the whereis, along with the different options associated with it, will be discussed in the next section.
Version of the whereis Command
This option “-V” along with the whereis command is used to check its version and the date it was built.
$ whereis -V
Example 1: Displaying the List of All Directories
Using the “-l” option, it will search through the entire file system and return the path that matches. So to display all directories information, you can type the following command:
$ whereis -l
Example 2: Locating Any Directory Path
The whereis command can also be used to locate any specific directory path as well as shown below:
$ whereis etc
When executed, the whereis command will search through specific directories and databases to locate the “etc” directory and return the path to it. There is only one etc. directory in Linux, but it will also show you the multiple directory paths if it contains as shown below:
$ whereis bash
As you can see, the bash has two different directory paths, which is why two paths are showing in the output.
Similarly, you can find the path of multiple commands using a single whereis command as shown below:
$ whereis etc bash$ whereis etc bash games
The above command will show the path of multiple commands in a single output that can be seen in the image.
Example 3: Display the Location of the Manual of Any Command
Manual is one of the most important commands in Linux, especially if you want detailed information about any command. So if you want to display the path of the manual page for any command, you need to use the “m” option by typing:
$ whereis -m ls
The above command in Linux is used to search for the location of the “man” page files for the “ls” command on the system and then display it on the terminal. The same thing can also apply to find the man page path for multiple commands as shown below:
$ whereis -m ls sudo
Example 4: Showing Only Binary Files
If you want to show only the binary path for any command, then you need to type:
$ whereis -b bash
The above can be used to display the binary path only for the bash command.
The whereis command in Linux is a useful tool that helps identify the location of files and commands on the system. It scans through specific directories and databases to locate a particular command or file’s binary, source, and manual page files. This article has provided an in-depth understanding of the whereis command and its various options, which can be used to perform specific file searches.