Linux Whereis Command

Linux Whereis Command

Most users, while working on a command prompt, need to find out the location of the binary or executable of a file for a command.

In this case, find and whereis both commands can be used. But, the find command is much more time-consuming as compared to the whereis command.

The Linux whereis command also produces accurate results quickly as compared to the find command. So, users prefer to use the whereis command for this purpose.

In this tutorial, we will demonstrate how to use the whereis command in a Linux system.

The whereis command allows you to locate the binary, source code, and manual page files for a given command. It’s a command-line utility that is used to search for executable files of a program, configuration files, and its man pages in restricted Linux directories.

Linux Whereis Command Syntax

The the syntax is as follows:

whereis [OPTIONS] filename

When no option is used, it searches for binary executables, source, and manual files for a specified command that is used as an argument. whereis, by default, finds the files of the given command in the form of hard-coded paths and directories that are listed in the environment variables. 

How To Use the Whereis Command in Linux

The whereis command consumes very little time to locate the command executable binaries, source files, and manual sections. If the specified command doesn’t exist, it only displays the name of the command on the terminal. Using the option -l, we can print the information about directories where the whereis command searches for. 

where -l

where l option

Using the whereis command, we can search for the binary, source, and manual page files, single or multiple specified commands, or a program. We can also limit the search locations to find binaries, source files, and man sections using different options along with the whereis command. Let’s explore how to use the whereis command with the help of some examples.

Linux Whereis Command Examples

Below, we have mentioned various examples that will help you to understand the basics of the whereis command:

Example 1: Find the location of the command

For example, we want to get the information about the grep command binary location, source code, and man page file. Type the following command to view the complete path location of the grep command:

whereis grep

whereis grep

Example 2: Use multiple arguments with the Whereis Command

Using the whereis command, we can get the path information about multiple commands. In other words,  the multiple arguments can use with the whereis command. 

whereis chmod pwd bash

whereis multiple commands

This command displays the binary, source code, and manual page information of multiple commands.

Example 3: Search only the command Binaries

If we want to search only the program or command binaries then, use the option -b. For example, we want to search the binary file of the netstat command. Type the following command to get the binary files of a particular command:

whereis -b netstat

whereis b option

Example 4: Search only the source code files

For example, using the option -s along with the whereis command, we can search for source files of a specified command, as follows:

To search only for the source files, use the -s option.

whereis -s pwd

whereis s pwd

If the source files exist, The whereis command will display the pwd command locations.

Example 5: Search for manual paths of command

When we use the whereis command with option -m, it will print the manual file path of a specified command. For example, we want to display the manual path sections of the ‘whoami’ command. Use the following command to print the manual path of the whoami command:

whereis -m whoami

whereis m option

Example 6: Limit the location for searching binaries, sources, and manual paths

we can also limit the locations where the whereis command searches for source code, binaries, and manual page files by using the -S , -B, and -Mrespectively.

We can display the help information related to the whereis command using the following command:

whereis -h

whereis help

To display the information about the version of the whereis command, use the below-mentioned command:

whereis -V

whereis version

Whereis Options

The whereis command accepts the following options:

Options Purpose
-b Search for command binaries.
-m Search for command manual paths.
-f Specify the search scope.
-s Search for command sources files.
-B Limit the locations to search for binaries.
-M Limit the locations to search for man paths.
-u Search for unusual entries.
-S Limit the locations to search for source code files.
-V Prints version details and exit.
-h Display whereis command help and exit.

 

Conclusion

We demonstrated the basics of the Linux whereis command in this tutorial. sing the different scenarios and examples, we elaborated the usage of the whereis command, along with the number of options we can use with this command. The above-mentioned examples are useful for Unix or Linux users. Please follow the above guidelines and let us know about your feedback via comments and we’ll get back to you as soon as we can. 

0 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
You May Also Like