---
title: "How to Use whereis to Locate System Commands on Linux"
description: "Learn how to locate Linux system commands with this ATA Learning tutorial on the whereis utility through examples!"
canonical: "https://adamtheautomator.com/whereis/"
---

# How to Use whereis to Locate System Commands on Linux

> Learn how to locate Linux system commands with this ATA Learning tutorial on the whereis utility through examples!

Source: https://adamtheautomator.com/whereis/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Use whereis to Locate System Commands on Linux](https://adamtheautomator.com/wp-content/uploads/2023/08/whereis.jpg)

# How to Use whereis to Locate System Commands on Linux

[![](https://secure.gravatar.com/avatar/4857309ffa2757ccd895816d23abcbed03b21a0557487e69114a512023cfc095?s=192&d=mm&r=g)Deborah Emeni](https://adamtheautomator.com/author/deborah-emeni/)30 August 20236 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Linux](/tag/linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Locating a Command’s Binary File via the whereis Command](#locating-a-commands-binary-file-via-the-whereis-command)
*   [Employing Located Commands](#employing-located-commands)
*   [Filtering the Search Result by the Base Name](#filtering-the-search-result-by-the-base-name)
*   [Locating Commands via a Custom Set of Directories](#locating-commands-via-a-custom-set-of-directories)
*   [Finding a Command’s Documentation](#finding-a-commands-documentation)
*   [Accessing a Command’s Source Code Files](#accessing-a-commands-source-code-files)
*   [Searching for Unusual Entries](#searching-for-unusual-entries)
*   [Performing Complex Searches Using Different Switches](#performing-complex-searches-using-different-switches)
*   [Conclusion](#conclusion)

Are you scuffling with the challenge of locating essential system commands within your operating system (OS)? Do not sweat it, as it is a common hurdle. But on the bright side, you can count on the `whereis` command to lend you a hand.

In this tutorial, you will learn how to effectively use the `whereis` command as a tool that swiftly guides you to the precise locations of those elusive commands and utilities.

Dive into the world of `whereis` and take full command of your system!

## Prerequisites

Before diving in, ensure you have a Linux machine (preferably [Ubuntu](https://ubuntu.com/)) with a terminal emulator.

Related:[How to Install Ubuntu 20.04 \[Step-by-Step\]](https://adamtheautomator.com/install-ubuntu/)

## Locating a Command’s Binary File via the `whereis` Command

Are you constantly dealing with aliases, symbolic links, and different versions of the same command? If yes, knowing a command’s binary file path via the `whereis` command is especially helpful.

Below is the basic syntax for the `whereis` command:

*   `[options]` – Considered as optional command-line arguments, these options let you specify the type of files to search for and the locations to search in.
*   `<command_name>` – Specifies the command you wish to locate the binary file of.

```bash
whereis [options] <command_name>
```

To see how the `whereis` command works in action, follow these steps:

Open your terminal, and execute the following `whereis` command to list the number of options available.

```bash
whereis -h
```

The following list in your terminal shows all the options you can use with the `whereis` command. Knowing these options provides you more control over how you want the `whereis` command to operate.

![Viewing all options available for the whereis command](https://adamtheautomator.com/wp-content/uploads/2023/08/image-278.png)

Viewing all options available for the `whereis` command

Now, run the below `whereis` command to locate the path of the `ls` (or any other) command’s binary file, manual pages, and source files.

> 💡 _Without specifying options, the `whereis` command only searches for three types of files: binaries, manuals, and source files in their default locations._

```bash
whereis ls
```

In the output below, you can see two paths as follows:

| Path | File Type | Details |
| --- | --- | --- |
| /usr/bin/ls | Binary file | Indicates the binary file for the ls command is located in the /usr/bin directory. This directory contains all the essential commands installed on your system. |
| /usr/share/man/man1/ls.1.gz | Manual page | Signifies the manual page for the ls command is located in the /usr/share/man/man1 directory. This directory holds all the manual pages installed on your system. The .gz extension indicates that the manual page is currently compressed. |

![Locating the ls command’s binary file path](https://adamtheautomator.com/wp-content/uploads/2023/08/image-277.png)

Locating the `ls` command’s binary file path

> 💡 _Remember that the exact path can vary depending on your Linux distribution, version, and system configuration._

## Employing Located Commands

Now that you know the location of your chosen command, you can employ that command in various ways. One example is you can run the command directly by specifying its path. Or automate tasks in a custom script that runs the command.

To employ located commands, the `ls` command, for example:

Execute the following command to run the `ls` command from its specified path directly.

Related:[How To Wrangle Ubuntu Environment Variables](https://adamtheautomator.com/ubuntu-environment-variables/)

```bash
/usr/bin/ls
```

If the specified path is correct, you will see the files and folders in the working directory listed, as shown below.

![](https://adamtheautomator.com/wp-content/uploads/2023/08/image-280-1024x123.png)

Alternatively, run the below command to add the directory containing the command to your system’s PATH environment variable. Doing so allows you to execute the command from anywhere on the system.

> 💡 _If the command is in the current directory, the shell does not search for the command in the `PATH` environment variable._

```
export PATH=$PATH:/usr/bin
```

Once added to the PATH environment variable, you can run the command (i.e., `ls`) without specifying the full path, as shown below.

![](https://adamtheautomator.com/wp-content/uploads/2023/08/image-279-1024x143.png)

## Filtering the Search Result by the Base Name

The `whereis` command also provides several switches you can use to modify its behavior and enhance the search process. One example is the `-b` or `--basename` switch, which lets you avoid ambiguity by narrowing the search to the exact binary you are interested in.

Execute the following `whereis` command to find the path of the `ls` command, limited to its base name (`-b` or `--basename`).

```bash
whereis -b ls
```

If successful, you will see the following output. Notice that only one path is listed,_**/usr/bin/ls**_, the path to the `ls` command’s binary file.

![Filtering the search result by the command’s base name](https://adamtheautomator.com/wp-content/uploads/2023/08/image-287.png)

Filtering the search result by the command’s base name

## Locating Commands via a Custom Set of Directories

Explicitly defining directories where the `whereis` command should search for binary executables can help improve the performance of the search process.

On that note, the `B` or `--path` switch can help limit the search to specific directories. This switch is beneficial when searching for commands in large filesystems or complex directory structures.

To see how the `B` or `--path` switch works:

Run the following command to search for the `ls` command’s binary files (`-f`) only in the `/usr/local/bin` and `/opt/bin` directories.

Notice that you specify multiple directories in the command by separating them with colons (`:`) on Unix-like systems (or semicolons (`;`) on Windows).

```bash
whereis -B /usr/local/bin:/opt/bin -f ls
```

![Searching for a command’s binary files on specific directories](https://adamtheautomator.com/wp-content/uploads/2023/08/image-283.png)

Searching for a command’s binary files on specific directories

## Finding a Command’s Documentation

When working in environments with limited or no internet connectivity, knowing the paths of the manual pages is particularly valuable.

To find a command’s documentation:

Execute the following command to search for manual pages (`-m` or `--man`) for the `ls` command, excluding binary and source code files related to the command.

```
whereis -m ls
```

Notice below that only the manual page for the `ls` command is listed in the output.

![Finding the ls command’s manual page](https://adamtheautomator.com/wp-content/uploads/2023/08/image-288.png)

Finding the `ls` command’s manual page

## Accessing a Command’s Source Code Files

Similar to explicitly finding a command’s documentation, you can search for a command’s source code files by appending the `-s` or `--source` switch. Accessing the source code can provide insight into how a command is implemented, helping you understand its functionality and behavior more deeply.

Being able to access a command’s source code files is especially helpful when you wish to:

*   Customize or modify a command’s behavior directly.
*   Diagnose issues or troubleshoot problems related to a command’s behavior.
*   Contribute improvements or fixes to the project (if the command is open source) if you are familiar with the source code.

To access a command’s source code files:

Run the below `whereis` command to find the source code files of the `ls` command.

```bash
whereis -s ls
```

Why does the `ls` command not have source code files? The availability of source code files for some commands, like the `ls` command, depends on several factors.

These factors include the command itself, the distribution of Linux you are using, and how the distribution packages and manages its software.

![Searching for the ls command’s source code files](https://adamtheautomator.com/wp-content/uploads/2023/08/image-284.png)

Searching for the `ls` command’s source code files

## Searching for Unusual Entries

Unusual entries are files that do not have exactly one entry of each requested type: binary, manual, and source. Searching for unusual entries also helps with troubleshooting error messages.

Execute the following command to search for the `ls` command and identify unusual (`-u` or `--usage`) entries.

```bash
whereis -u ls
```

If the `ls` command has only two entries or more than three entries, as shown below, they are considered unusual entries.

![Searching for a command’s unusual entries](https://adamtheautomator.com/wp-content/uploads/2023/08/image-285.png)

Searching for a command’s unusual entries

## Performing Complex Searches Using Different Switches

You have seen how to use individual switches with the `whereis` command, but why not use multiple switches? The `whereis` command is not limited to only one switch when searching for commands.

Combining switches to perform complex searches lets you narrow your search or focus on specific types of files associated with a command.

To see how combined switches work:

Execute the following command to search for the `ls` command in the `/usr/bin` directory (`-B`), limited to manual pages (`-m`) and source code files (`-s`).

```
whereis -B /usr/bin -m -s ls
```

The output excludes binary files, as shown below. But since the `ls` command’s source code is not found, you can only see the path for the command’s manual page.

![Performing complex searches with combined switches](https://adamtheautomator.com/wp-content/uploads/2023/08/image-286.png)

Performing complex searches with combined switches

## Conclusion

In this tutorial, you learned that the `whereis` command is not just a tool but your trusty map in this terminal landscape. In the vast realm of the command line, the `whereis` command emerges as a true companion.

With this newfound knowledge, you can confidently navigate the intricate paths of Linux commands, accessing their binary files, manual pages, and source code.

Now, why not delve into the world of package management (i.e., `apt` for Debian/Ubuntu)? Cultivate a deeper insight into how the software ecosystem on your Linux system works!

Related:[Learning Ubuntu Apt Get Through Examples](https://adamtheautomator.com/ubuntu-apt-get/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fwhereis%2F&text=How%20to%20Use%20whereis%20to%20Locate%20System%20Commands%20on%20Linux)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fwhereis%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fwhereis%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

![](https://adamtheautomator.com/wp-content/uploads/2024/03/pipe-command-in-linux-1.jpg)

### [Unleashing the Power of the Pipe Command in Linux](/pipe-command-in-linux/)

Unlock the prowess of the pipe command in Linux to streamline tasks, boost productivity, and simplify complex operations effortlessly!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
