The “whereis” Command in Linux [10 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The whereis command in Linux is used to locate the binary, source, and manual page files of specified command/s. With this command, you will also be able to search for a particular type of file path. There are many other uses of this command. In this article, I will demonstrate the most helpful uses of the command with practical examples.

A. Description

The whereis command in Linux returns the binary, source, and manual page file locations of desired commands. It looks into the executive files in places specified by both $PATH and $MANPATH variables.

B. Syntax

The syntax of the whereis command in Linux is pretty straightforward. Below is the syntax for the command.

whereis [options] name...
Note: In the syntax above, the OPTION enclosed by the square bracket means it is not mandatory and three dots after the name mean multiple names can be used at a time

C. Options

The whereis command in Linux comes with several options to modify user experience. You can find these options on the man page of this command. However, I have listed some useful options below for your convenience.

man whereis

Useful Options

  • -b: Searches for binary files.
  • -B: Limit searching spaces for binary files.
  • -f: Terminates the directory list and signals the start of filenames.
  • -l: Display the list of effective lookup locations.
  • -m: Searches for manual page files.
  • -M: Limit searching spaces for manual page files.
  • -s: Searches for source files.
  • -M: Limit searching spaces for source files.
  • -u: Searches for unusual entries.
Note: The options in Linux CLI (Command Line Interface) are all case-sensitive, So be cautious while using them

Practical Examples of the “whereis” Command in Linux

Various utilization of the command whereis is available in Linux. You can adjust the search criterion of file locations using a number of options. Below I have given some practical examples of the command for your better understanding.

Example 1: Listing All the Locations to Search Using the “whereis” Command in Linux

Using the whereis command in Linux you can view a list of all the locations that are searched while executing the command. These are the effective lookup paths. To print these paths you will need to use the -l option. In this example, I will show you the process of listing all the effective locations in my system. You can do the same by following the steps below.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

whereis -l

➌ Now, press the ENTER button.

Output >

In this given image, you can see that I have printed all the effective locations used for searching by the whereis command.Listing all the search locations using the whereis command in linux.

Example 2: Finding Locations of the Binary, Source, and Manual Files of a Command

You can find the Binary, Source, and Manual Page file locations of a command using the whereis command in Linux. In this example, I will find out the locations of the touch command. You can follow the steps below to do the same.

Steps to Follow >

➊ At first launch the Ubuntu Terminal.

➋ Type the following command in the command line:

whereis touch

➌ Press the ENTER button.

Output >

In the image below, you can see that I have shown the Binary and Manual Page location of the touch command. As the whereis command did not find the Source file in its effective directories the Source file is not shown here.Displaying Binary and Manual Page file of a command using the whereis command in linux.


Similar Readings


Example 3: Finding Locations of the Binary, Source, and Manual Files of Multiple Commands

You can find the Binary, Source, and Manual Page file locations of multiple commands using the whereis command in Linux. To do so you will just need to provide the list of commands after the whereis command. In this example, I will find out the locations of the touch and bash commands. You can follow the steps below to do the same.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Type the following command in the command line:

whereis touch bash

➌ Hit the ENTER button.

Output >

In the given snapshot, you can see that I have shown the Binary and Manual Page file locations of the two desired commands. Since the whereis command did not find the Source files in its effective directories, the Source files are not shown here.Displaying Binary and Source files of multiple commands using the whereis command in linux.

Example 4: Searching Only for the Binary File of a Command Using the “whereis” Command in Linux

Using the whereis command in Linux you can search for only the Binary file location of a command. To get this pathname you will need to use the -b option. In this example, I will show the Binary file location of the touch command. To do so you may follow the steps below.

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

whereis -b touch

➌ Now, press the ENTER button.

Output >

In the image below, you can see that I have printed only the Binary file location of the touch command.Finding only binary file using the whereis command in linux.

Example 5: Searching Only for the Source File of a Command Using the “whereis” Command in Linux

You can search for only the Source file location of a command using the whereis command in Linux. To get this pathname you will need to use the -s option. In this example, I will show the Source file location of the net command. You can follow the given process to get the same results.

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

whereis -s net

➌ Now, press the ENTER button.

Output >

In this image, you can see that I have printed only the Source file locations of the net command.Finding only source file of a command using the whereis command in linux.

Example 6: Searching Only for the Manual Page File of a Command Using the “whereis” Command in Linux

Using the whereis command with option -m in Linux you can search for only the Manual Page file location of a command. In this example, I will find out the Manual Page file location of the touch command. To do so you may follow the steps below.

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

whereis -m touch

➌ Now, press the ENTER button.

Output >

In the given image, you can see that I have shown only the Manual Page file location of the touch command.Finding only Manual Page file of a command using the whereis command in linux.

Note: In the following examples(examples 79) of using the options -B, -M, and -S, you must use the -f option as well. Application of these three options without the option -f will result in an error

Example 7: Limiting Searching Locations for the Binary File of a Command

You can limit the search space for the Binary file location of a command using the whereis command in Linux. To achieve this modification you will need to use the -B option and then a specified directory to search in. In this example, I will search the Binary file of the touch command in the /bin/ directory. You can follow the given process to get the same results.

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

whereis -b -B /bin/ -f touch

➌ Now, press the ENTER button.

Output >

In this next image, you can see that I have printed only the Binary file locations of the touch command from the /bin/ directory.Limiting search location of Binary file of a command using the whereis command in linux.

Example 8: Limiting Searching Locations for the Source File of a Command

Using the whereis command in Linux with the option -S you can limit the search space for the Source file location of a command. You will need to provide a directory path as well to search in. In this example, I will search the Source file of the bash command in the /etc/ directory. You can follow the given process to get the same results.

Steps to Follow >

➊ Launch the Ubuntu Terminal.

➋ Type the following command in the command prompt:

whereis -s -S /etc/ -f bash

➌ Press the ENTER button.

Output >

In the following image, you can see that I have printed only the Source file location of the bash command from the /etc/ directory.Limiting search space of the source file of a command using the whereis command in linux.


Similar Readings


Example 9: Limiting Searching Locations for the Manual Page File of a Command

You can limit the search space for the Manual Page file location of a command using the whereis command in Linux. You will need to use the -M option and then a specified directory to search in. In this example, I will search the Manual Page file of the touch command in the /usr/share/man/man1/ directory. You can do the same by following the steps below.

Steps to Follow >

➊ Go to the Ubuntu Terminal.

➋ Type the following command in the command line:

whereis -m -M /usr/share/man/man1/ -f touch

➌ Now, press the ENTER button.

Output >

In the image below, you can see that I have printed only the Manual Page file locations of the touch command from the /usr/share/man/man1/ directory.Limiting Search location of the Manual Page file of a command using the whereis command in linux.

Example 10: Searching for Unusual Entries Using the “whereis” Command in Linux

Using the whereis command in Linux with the -u option you can find files with unusual entries. To view the list of the unusual files you will need to run the command in the /bin directory. In this example, I will show you the process of listing all the unusual entries. To do the same you may follow the given steps.

Steps to Follow >

➊ Open the Ubuntu Terminal.

➋ At first, type the following command in the command to change the directory:

cd /bin

➌ After that, press the ENTER key.

➍ Now, type the desired command below:

whereis -m -u *

➎ Hit the ENTER button again.

Output >

In the below image, you can see that I have printed all the unusual entry locations using the whereis command.Listing all the unusual entries using the whereis command in linux.

Conclusion

In this article, I have illustrated the most frequent uses of the whereis command in Linux with practical examples. From now on, you will be able to locate all or any of the Binary, Source, and Manual Page Files of desired command/s with whereis. I hope, experimenting with these examples aids your journey with the command as well as helps you become a power user of Linux.


Similar Readings

Rate this post
Anonnya Ghosh

Hello there! I am Anonnya Ghosh, a Computer Science and Engineering graduate from Ahsanullah University of Science and Technology (AUST). Currently, I am working as a Linux Content Developer Executive at SOFTEKO. The strong bond between Linux and cybersecurity drives me to explore this world of open-source architecture. I aspire to learn new things further and contribute to the field of CS with my experience. Read Full Bio

Leave a Comment