Skip to content

whereis Command in Linux

Summary

The whereis command is a quick and simple utility in Linux used to locate the binary, source, and manual page files for a given command. It's helpful for understanding where a command is installed and accessing related documentation.

Introduction

The whereis command is a fundamental tool for Linux users, particularly system administrators and developers. It helps in locating the executables, source code (if available), and manual pages associated with a specified command. Unlike the which command, which only finds the executable file, whereis provides a broader search by default. This is helpful when you need to understand the complete context of a command or want to quickly access its documentation.

Use case and Examples

Basic Usage: Locate the Binary, Source, and Manual Pages of ls

whereis ls
This command will output the locations of the ls executable, its source code (if available and in a standard location), and its manual page.

Locate only the binary file of bash

whereis -b bash
Using the -b flag, this command specifically searches for the binary file associated with the bash command.

Locate only the manual page of ifconfig

whereis -m ifconfig
This command uses the -m flag to find the manual page for the ifconfig command.

Searching for a Command in Specific Directories

whereis -B /usr/bin /usr/sbin -M /usr/share/man/man1  apache2
This command searches for the apache2 command, specifically looking for binaries in /usr/bin and /usr/sbin and the manual pages in /usr/share/man/man1. This example demonstrates specifying directories for binary (-B) and manual page (-M) searches. It will not search default paths.

Commonly used flags

Flag Description Example
-b Searches only for binaries. whereis -b ls
-m Searches only for manual pages. whereis -m ls
-s Searches only for source code. whereis -s ls
-B <directories> Specifies directories to search for binaries. whereis -B /usr/bin:/usr/local/bin ls
-M <directories> Specifies directories to search for manual pages. whereis -M /usr/share/man/man1:/usr/local/man/man1 ls
-f Terminates the option list and signals the start of filenames. Useful if filenames start with -. whereis -f file1 file2


Share on Share on

Comments