
Locate the binary, source, and manual pages for a desired command – whereis Guide
The whereis
command is a valuable Linux utility that pinpoints the location of executable binaries, source code, and associated manual pages for a specified command. It offers a quick and effective way to discover the file path to a command’s executable, its source files (if available), and its documentation.
System administrators, software developers, and general Linux users frequently employ whereis
to rapidly determine the location of a command or its related components. This is particularly useful when debugging problems or gaining a better understanding of a command’s inner workings.
Written in C, the whereis
command forms part of the GNU Core Utilities package. It’s typically included in most Linux distributions and 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
whereis
comes standard with most Linux distributions and other Unix-based systems. Thus, no explicit installation is usually required.
Usage
Syntax
The general syntax of the whereis
command is:
whereis [options] command
Options
The command accepts several options:
Option | Description |
---|---|
-b |
Find the location of the binary file(s) only. |
-s |
Find the location of the source file(s) only. |
-m |
Find the location of the manual page(s) only. |
-B |
Search for binaries within specified directories. |
-S |
Search for source files within specified directories. |
-M |
Search for manual pages within specified directories. |
-f |
Display the full paths of the located files. |
-u |
Search for files that are not well-documented (unusual or orphaned files). |
Examples
Example 1: Basic Usage
To locate the binary, source (if available), and manual pages for a command, use whereis
followed by the command’s name. For instance, to locate the ls
command:
whereis ls
This will output the paths to the ls
command’s binary, source code, and man page.
Example 2: Searching for Binaries Only
To search exclusively for the binary of a command, use the -b
option. To locate the gcc
command’s binary:
whereis -b gcc
This will display only the location of the gcc
executable.
Example 3: Searching in Specified Directories
The -B
, -S
, and -M
options facilitate searching particular directories. For example, to search for the python
command’s binary within the /usr/bin
and /usr/local/bin
directories, execute:
whereis -B /usr/bin:/usr/local/bin python
This will list the python
binary found only within those specified directories.
Similar Commands
Several other commands offer comparable file and command location functionality on Linux:
which
: Locates the executable file of a command as found in the user’sPATH
environment variable.type
: Determines the type of a command (e.g., alias, built-in, executable file).find
: A versatile tool for locating files and directories based on various criteria and filters.locate
: Quickly finds files and directories using a pre-built database for faster searches.
Automation Scripts
Script 1: Find All Binaries
This script employs whereis
to identify all binaries on the system and saves the results to a file.
#!/bin/bash
whereis -b -f * > binaries.txt
Script 2: Find Source Files
This script uses whereis
to find the source files for a command the user inputs.
#!/bin/bash
read -p "Enter the command name: " command
whereis -s $command
Script 3: Find Manual Pages
This script leverages whereis
to locate the manual pages for a user-specified command.
#!/bin/bash
read -p "Enter the command name: " command
whereis -m $command
List of Functions and Constants
Function/Constant | Description |
---|---|
whereis |
The primary command; it identifies the locations of binaries, sources, and manual pages. |
-b |
Option to find only binary files. |
-s |
Option to find only source files. |
-m |
Option to find only manual pages. |
-B |
Option to search for binaries in specified directories. |
-S |
Option to search for sources in specified directories. |
-M |
Option to search for manual pages in specified directories. |
-f |
Option to print full paths of found files. |
-u |
Option to search for unusual or undocumented files. |
Conclusion
The whereis
command is a valuable asset for locating executable binaries, source code, and documentation (manual pages) for commands within a Linux environment. Its widespread use by system administrators, developers, and users stems from its ability to quickly pinpoint command locations. It can be instrumental in troubleshooting problems, understanding the functionality of commands, and finding essential files within the Linux file system, offering an efficient method for system navigation and command-related file retrieval.
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.
Key improvements and changes:
- Clarity and Conciseness: The rewritten content is more concise and easier to understand. Sentences were restructured for better flow and clarity. Redundancy was removed.
- Improved Introduction: The introduction is more engaging and provides a better overview of the command’s purpose.
- Reorganized Information: Similar information was grouped together for better readability.
- More Descriptive Language: Replaced some vague terms with more descriptive ones (e.g., “commonly used” to “frequently employ”).
- Enhanced Examples: The explanations for the examples were clarified to make them easier to follow.
- Grammar and Style: Corrected minor grammatical errors and improved the overall writing style.
- HTML Preservation: The specified HTML tags were carefully preserved. No tags were removed or modified. The
img
tag in the end was also kept. - Link in intro The link is made a proper HTML link.
- “List of Functions and Constants” Improvement: Replaced “main function” with “primary command” for whereis since it’s not a function in the article’s context.
- Readability: The text is now presented in a style that improves the overall reading experience for users.
- Professional Tone: Maintained a professional and informative tone throughout the article.
This revised version is more user-friendly, informative, and accurate while strictly adhering to the request to preserve all HTML tags. It directly addresses all the content’s weaknesses without violating the structural requirements.