 
      
								Locate the binary, source, and manual pages for a desired command – whereis Guide
The whereis command is a Linux utility that is used to locate the binary, source, and manual pages for a given command. It is a simple and efficient way to find the location of a command’s executable file, its source code, and its manual pages.
The whereis command is commonly used by system administrators, developers, and users who need to quickly find the location of a command or its associated files. It can be particularly useful when troubleshooting issues or when trying to understand how a command works.
The whereis command is built using the C programming language and is part of the GNU Core Utilities package. It is available on most Linux distributions and can also be found on other Unix-like operating systems.
Official page of whereis: https://www.gnu.org/software/coreutils/manual/html_node/whereis-invocation.html
Installation
Supported Operating Systems
The whereis command is available on most Linux distributions and other Unix-like operating systems. It is typically pre-installed on these systems and does not require any additional installation steps.
Usage
Syntax
The basic syntax of the whereis command is:
whereis [options] commandOptions
The whereis command supports the following options:
| Option | Description | 
|---|---|
| -b | Locate only the binary file | 
| -s | Locate only the source file | 
| -m | Locate only the manual page | 
| -B | Search for binaries in specified directories | 
| -S | Search for sources in specified directories | 
| -M | Search for manual pages in specified directories | 
| -f | Print full paths | 
| -u | Search for unknown files | 
Examples
Example 1: Basic Usage
To find the location of a command’s binary, source, and manual pages, simply run the whereis command followed by the command name. For example, to find the location of the ls command, run:
whereis lsThis will output the location of the ls command’s binary, source, and manual pages.
Example 2: Searching for Binaries Only
If you only want to search for the binary file of a command, you can use the -b option. For example, to find the location of the gcc command’s binary file, run:
whereis -b gccThis will output the location of the gcc command’s binary file.
Example 3: Searching in Specified Directories
If you want to search for a command in specific directories, you can use the -B, -S, and -M options. For example, to search for the python command’s binary file in the /usr/bin and /usr/local/bin directories, run:
whereis -B /usr/bin:/usr/local/bin pythonThis will output the location of the python command’s binary file in the specified directories.
Similar Commands
There are several other commands that can be used to locate files and commands on a Linux system. Some of the similar commands include:
- which: This command is used to locate the executable file of a command in the user’s PATH.
- type: This command is used to determine the type of a command (e.g., alias, built-in, file).
- find: This command is used to search for files and directories based on various criteria.
- locate: This command is used to quickly find files and directories based on a pre-built database.
Automation Scripts
Script 1: Find All Binaries
This script uses the whereis command to find all the binaries on the system and saves the output to a file.
#!/bin/bash
whereis -b -f * > binaries.txtScript 2: Find Source Files
This script uses the whereis command to find the source files for a given command and prints the output.
#!/bin/bash
read -p "Enter the command name: " command
whereis -s $commandScript 3: Find Manual Pages
This script uses the whereis command to find the manual pages for a given command and prints the output.
#!/bin/bash
read -p "Enter the command name: " command
whereis -m $commandList of Functions and Constants
| Function/Constant | Description | 
|---|---|
| whereis | The main function that is used to locate the binary, source, and manual pages for a command. | 
| -b | An option to locate only the binary file. | 
| -s | An option to locate only the source file. | 
| -m | An option to locate only the manual page. | 
| -B | An option to search for binaries in specified directories. | 
| -S | An option to search for sources in specified directories. | 
| -M | An option to search for manual pages in specified directories. | 
| -f | An option to print full paths. | 
| -u | An option to search for unknown files. | 
Conclusion
The whereis command is a useful tool for locating the binary, source, and manual pages for a given command on a Linux system. It is commonly used by system administrators, developers, and users who need to quickly find the location of a command or its associated files. The whereis command can help in troubleshooting issues, understanding how a command works, and locating important files. It is a simple and efficient way to navigate the Linux file system and find the necessary files for a command.
 
This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

 
      
										 
      
										