LinuxCommandLibrary

whereis

Locate binary, source, and manual files

TLDR

Locate binary, source and man pages for SSH

$ whereis [ssh]
copy

Locate binary and man pages for ls
$ whereis -bm [ls]
copy

Locate source of gcc and man pages for Git
$ whereis -s [gcc] -m [git]
copy

Locate binaries for gcc in /usr/bin/ only
$ whereis -b -B [/usr/bin/] -f [gcc]
copy

Locate unusual binaries (those that have more or less than one binary on the system)
$ whereis -u *
copy

Locate binaries that have unusual manual entries (binaries that have more or less than one manual installed)
$ whereis -u -m *
copy

SYNOPSIS

whereis [options] [-bmsu] [-B dir ...] [-M dir ...] [-S dir ...] command ...

PARAMETERS

-b
    Search only for binaries.

-m
    Search only for manual sections.

-s
    Search only for sources.

-u
    Search for unusual entries, meaning those that do not have one entry of each type requested. For example, whereis -m -u ls will list files that have no man page associated with them.

-B dir ...
    Limit the search for binaries to the specified directories. Multiple directories can be listed.

-M dir ...
    Limit the search for man pages to the specified directories. Multiple directories can be listed.

-S dir ...
    Limit the search for sources to the specified directories. Multiple directories can be listed.

-f
    Terminates the last directory list and signals the beginning of program names. This is useful when the last list of directories might be mistaken for program names.

-l
    List the effective search paths that whereis is using for binaries, man pages, and sources. This option is helpful for debugging search path issues.

DESCRIPTION

The whereis command is used to locate the binary, source, and manual page files for a specified command name. It operates by searching a fixed set of standard system locations for Linux programs, as well as considering paths defined in environment variables like PATH and MANPATH. This utility is particularly useful for quickly finding where a program's executable, its underlying source code, or its documentation resides on the filesystem. It's a handy tool for system administrators, developers, or anyone needing to understand software installations or troubleshoot issues related to file locations.

Unlike commands like which, which primarily finds the executable that would be run from your shell, or find, which performs general file searches, whereis is optimized for finding program-related components. It can provide multiple file types (binaries, sources, and man pages) in a single query, making it efficient for specific program-centric lookups rather than general file searches.

CAVEATS

whereis primarily relies on a set of hardcoded standard paths and configured environment variables (like PATH and MANPATH). It might not locate programs installed in highly non-standard or custom directories unless those directories are explicitly specified using the -B, -M, or -S options.

It does not perform a general filesystem search like find, nor does it resolve shell aliases or functions like which. Its scope is limited to finding program-related components based on its predefined search logic.

SEARCH PATHS

whereis operates by looking in a number of built-in, hard-coded standard directories typically used for binaries (e.g., /bin, /usr/bin, /usr/local/bin), manual pages (e.g., /usr/share/man), and source code (e.g., /usr/src). These default search locations can be augmented or overridden by using the -B, -M, and -S options, allowing users to specify additional directories to search for each type of file. The PATH and MANPATH environment variables also contribute to the overall search scope.

DISTINCTION FROM 'WHICH'

While both whereis and which help locate commands, they serve different purposes. which specifically identifies the exact executable that would be invoked by your shell if you typed the command name, respecting the current PATH environment variable, aliases, and shell functions. In contrast, whereis provides a broader lookup, aiming to find all associated files (binary, source, and manual pages) for a given command, often searching a wider set of standard system directories, without considering shell-specific behaviors like aliases.

HISTORY

whereis has been a fundamental Unix utility for many decades, providing a direct and efficient method to locate program components. Its core functionality, focused on finding binaries, sources, and man pages, has remained remarkably consistent across various Unix-like operating systems. While modern package managers handle installation and tracking, whereis continues to be a quick, low-level tool for direct file location queries on a system, often used in scripting and system administration tasks.

SEE ALSO

which(1), find(1), locate(1), man(1)

Copied to clipboard