Skip to main content
Engineering LibreTexts

05-B.5.3: Searching for Files on Linux - whereis Command

  • Page ID
  • The whereis Command

    The whereis command locates the binary, source and manual files for the specified command names. The supplied names are first stripped of leading pathname components and any (single) trailing extension of the form .ext (for example: .c) Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the desired program in the standard Linux places, and in the places specified by $PATH and $MANPATH.

    Syntax :

    $ whereis [options] [directory name] {file name}

    Command Options :

    -b Search for binaries.
    -m Search for manuals.
    -s Search for sources.
    -u Only show the command names that have unusual entries. A command is said to be unusual if it does not have just one entry of each explicitly requested type. Thus 'whereis -m -u *' asks for those files in the current directory which have no documentation file, or more than one.
    -B list Limit the places where whereis searches for binaries by a whitespace-separated list of directories.
    -M list Limit the places where whereis searches for manuals and documentation in Info format, by a whitespace-separated list of directories.
    -S list Limit the places where whereis searches for sources by a whitespace-separated list of directories.
    -f Terminates the directory list and signals the start of filenames. It must be used when any of the -B, -M, or -S options are used.
    -l Output the list of effective lookup paths that whereis is using. When none of -B, -M, or -S is specified, the option will output the hard-coded paths that the command was able to find on the system.
    -h, --help Display help text and exit.
    -V, --version Display version information and exit.
    A terminal window showing several different incantations of the whereis command
    Figure \(\PageIndex{1}\): The whereis Command. ("whereis command" by Patrick McClanahan is licensed under CC BY-SA 4.0)

    The whereis command accepts a single argument - ping, or multiple arguments - netcat and uptime. The output shows the path to the execuatable, and to the man page file. Where we entered multiple arguments, the output shows the path for the executable and the man page for all the arguments. Where an argument exists in multiple locates, such as touch, it outputs the path to all known executables and manuals. Notice in this example the touch command is located in two places on the system BUT the man pages have only a single copy.

    Adapted from:
    "whereis command in Linux with Examples" by Suraj1994, Geeks for Geeks is licensed under CC BY-SA 4.0

    • Was this article helpful?