whereis

file searchingLinux/Unix
The whereis command is one of the most frequently used commands in Linux/Unix-like operating systems. whereis Locate the binary, source, and manual page files for a command

Quick Reference

Command Name:

whereis

Category:

file searching

Platform:

Linux/Unix

Basic Usage:

whereis [options] [arguments]

Common Use Cases

    Syntax

    whereis [options] name...

    Options

    Option Description
    -b Search only for binaries
    -m Search only for manual sections
    -s Search only for sources
    -u Search for unusual entries (non-standard locations)
    -B list Limit search for binaries to the provided colon-separated list of directories
    -M list Limit search for manual sections to the provided colon-separated list of directories
    -S list Limit search for sources to the provided colon-separated list of directories
    -f Terminate the directory list and signal the start of filenames
    -l Output effective search paths
    -q Quiet mode; return 0 if any files were found, 1 if none were found
    -h, --help Display help information and exit
    -V, --version Display version information and exit

    Output Format

    The output of whereis typically consists of:

    name: binary_path manual_path source_path
    

    For example:

    ls: /bin/ls /usr/share/man/man1/ls.1.gz
    

    Where each component is displayed only if it exists.

    Examples

    How to Use These Examples

    The examples below show common ways to use the whereis command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    # Find the locations of the 'ls' command whereis ls
    # Find the locations of multiple commands whereis ls grep find
    # Find only the binary for a command whereis -b ls
    # Find only the manual page for a command whereis -m grep
    # Find only the source code for a command whereis -s bash
    # Advanced Examples Advanced # Find binaries in a specific directory whereis -B /usr/local/bin -f ls # Find manual pages in a specific directory whereis -M /usr/share/man/man1 -f grep # Find all components with limited search paths whereis -b -m -B /bin -M /usr/share/man find # List all searched directories for binaries whereis -l # Search only in specific binary and manual directories whereis -B /usr/bin -B /bin -M /usr/share/man -f ls # Find a command but suppress normal output and return success if any files were found whereis -q bash

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `whereis` command is a useful utility that helps locate the binary, source, and manual page files for a specified command. It's particularly valuable for system administrators and developers who need to quickly find where a program is installed or access its documentation and source code. **Core Functionality:** 1. **Comprehensive Locating**: whereis searches for three types of files related to a command: - Binary executable files - Manual pages - Source code files 2. **Multiple Commands**: It can locate files for multiple commands in a single invocation. 3. **Selective Searching**: Users can restrict the search to specific file types (binary, manual, or source) and directories. 4. **Standard Locations**: whereis is optimized to search in standard system locations, making it faster than more general-purpose tools like `find`. **Common Use Cases:** 1. **Command Verification**: Quickly check if a command is installed and where it's located. 2. **Documentation Access**: Find the manual page for a command when you need to learn how to use it. 3. **Source Code Examination**: Locate source code files for studying or modifying software. 4. **System Administration**: Determine which version of a command is being used when multiple versions are installed. 5. **Script Automation**: Use whereis in scripts to determine if required commands are available and where they're located. **Technical Details:** 1. **Search Paths**: whereis uses a predefined set of standard directories for searching, including: - Binaries: /bin, /usr/bin, /sbin, /usr/sbin, etc. - Manual pages: /usr/share/man, /usr/local/man, etc. - Source code: /usr/src, etc. 2. **Path Listing**: The -l option shows all the directories whereis will search, which can be helpful for understanding why certain files are or aren't being found. 3. **Name Matching**: whereis looks for files with names that match the command name, potentially with suffixes for manual pages (e.g., .1 through .9) and standard source code extensions. 4. **Path Customization**: The -B, -M, and -S options allow customizing search paths for binaries, manual pages, and source code respectively. **Comparison with Related Commands:** 1. **which**: The `which` command only locates the executable file that would be executed by the shell, based on the user's PATH environment variable. It's more focused but provides less information than whereis. 2. **locate**: The `locate` command searches a database of all files on the system, not just commands. It's faster for general file searching but doesn't categorize results like whereis does. 3. **find**: The `find` command can search for any files anywhere on the system, but it's slower and requires more specific criteria than whereis. **Limitations and Considerations:** 1. **Database Dependency**: Unlike `find`, whereis doesn't perform a real-time search of the entire filesystem. It focuses on standard locations, which makes it faster but potentially less comprehensive. 2. **Command vs. File Distinction**: whereis is designed for locating command-related files, not general files. For general file searching, tools like `locate` or `find` are more appropriate. 3. **Source Code Limitations**: The source code search functionality may not be reliable on all systems, as source code is often not installed by default on production systems. **Historical Context:** whereis has been part of Unix-like systems for decades, providing a quick way to locate command-related files before more sophisticated package management systems were developed. Despite the evolution of package managers and file indexing tools, whereis remains valuable for its simplicity, speed, and focus on command-related files. **Best Practices:** 1. **Use with which**: Combine whereis with which when you need to determine exactly which binary will be executed by the shell: ``` whereis python # Shows all Python-related files which python # Shows which Python binary would be executed ``` 2. **Verify Manual Pages**: Use whereis to check if a command has manual pages available before trying to view them with man: ``` whereis -m command ``` 3. **Script Usage**: When using whereis in scripts, consider using the -q option for non-verbose success/failure indication: ``` if whereis -q command; then echo "Command is available" else echo "Command is not available" fi ``` 4. **Custom Path Searching**: For non-standard installations, use the -B, -M, or -S options to specify additional search directories.

    Related Commands

    These commands are frequently used alongside whereis or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the whereis command works in different scenarios.

    $ whereis
    View All Commands