whereis Command in Linux

November 30, 2023

Introduction

The Linux whereis command locates the binary, source, and manual page files for a command. The whereis utility provides a concise way to gather information about a target command and allows users to analyze the file structure of a Linux system

This article will teach you about Linux whereis command through its use case examples.

‌Prerequisites

  • Linux system (this tutorial uses Ubuntu 22.04).
  • Access to the terminal.

Linux whereis Command Syntax

The whereis command syntax is:

whereis [options] [command_name]

Running the command without any options or [command_name] in Ubuntu results in an error message:

whereis
whereis command output

However, in other Linux distributions, doing the same could produce general output about commonly used commands. The output depends on the system.

Linux whereis Command Options

The‌ options customize whereis, producing specifically tailored output. The common arguments are:

OptionDescription
-bPrints only executables.
-BPrints executable within a specific directory.
-mDisplays only manual pages.
-MDisplays manual pages but within a particular directory.
-sShows only source files.
-SShows only source files but within a specified directory.
-uSearches for unusual entries.
-lLists specified file's components.
-fTerminates the last component in the file path. It is always used with -B, -M, or -S.
-hDisplays help information.
-VPrints version info.

whereis Command in Linux: Examples

The whereis command works with different options and has many use-case examples. The following texts elaborates on the most important examples.

Example 1: Find Command Location

To locate a command, run whereis with the target command name. For instance, find the ls command location with the following:

whereis ls
whereis ls terminal output

The output indicates where the ls executable file is and shows the man page location.

Example 2: Locate Multiple Commands

To find more than one command, type whereis and each [command_name] separated by a space. For instance, find the locations for ls, cat, and whoami with:

whereis ls cat whoami
whereis ls cat whoami terminal output

Example 3: Identify whereis Target Locations

By default, whereis looks for a command's files in pre-defined paths and directories specified in the environment variables.

To identify the searched directories, use the -l option.

For example:

whereis -l
whereis -l terminal output

This output shows the specific directories that whereis examines while searching command-related files.

Example 4: Locate the Command Binary

To find only the command's executable (binary) file, run whereis with -b:

whereis -b [command_name]

For example, find the ls binary file:

whereis -b ls
whereis -b ls terminal output

‌Unlike the previous example, the output prints only the path to the executable and excludes the manual page.

Example 5: Find Binary in a Specific Location

To pinpoint command executables exclusively within particular directories, use the -B and -f options. The -B argument designates a specific directory, while the -f option, always paired with -B, specifies that the subsequent term in the command is the target command.

The syntax is:

whereis -b -B [directory_name] -f [command_name]

For example, locate ls binaries within the /bin directory with the following:

whereis -b -B /bin -f ls
whereis  -b -B /bin -f ls terminal output

Example 6: Locate the Man Page

If the goal is only to show the manual page location, run the command with -m.

whereis -m [command_name]

For instance:

whereis -m ls
whereis -m ls terminal output

The output shows only the ls manual page location.

Example 7: Find Unusual Entries

 To search for unusual entries that deviate from the standard or expected location, use the -u argument. For example, find all unusual entries in the current directory with:

whereis -s *
whereis -s * command terminal output

Conclusion

After reading this article, you should know how to use the whereis command and its options by following use-case examples.

Next, read about other important commands in this Linux commands cheat sheet.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
Linux: Add a Directory to PATH
September 22, 2022

PATH is an environmental variable that shows Linux where to search for executables (binaries). Read this guide and learn how to add a directory to PATH...
Read more
Linux File Permissions Tutorial
May 15, 2024

The file permission feature specifies how much power each user has over a given file or directory. To understand Linux file permissions, you need to get to know the...
Read more
How to Create a File in Linux
July 11, 2024

Creating a file in Linux might seem straightforward, but there are some surprising and clever techniques. In this tutorial learn how to create a new file in Linux...
Read more
How to Delete a File in Linux
September 7, 2023

Deleting unnecessary files in Linux is a routine task, This article lists the most commonly used commands and tools to remove unwanted files from your Linux system...
Read more