Skip to main content
Engineering LibreTexts

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

  • Page ID
    32141
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)

    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 :

    Option Option Meaning
    -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.
    pbmac@ubuntu $ whereis ping
    ping: /usr/bin/ping /usr/share/man/man8/ping.8.gz
    pbmac@ubuntu $ whereis netcat uptime
    netcat: /usr/bin/netcat /usr/share/man/man1/netcat.1.gz
    uptime: /usr/bin/uptime /usr/share/man/man1/uptime.1.gz
    pbmac@ubuntu $ whereis touch
    touch: /usr/bin/touch /usr/share/man/man1/touch.1.gz
    pbmac@ubuntu $
    
    

    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


    05-B.5.3: Searching for Files on Linux - whereis Command is shared under a CC BY-NC license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?