Jump to content

Welcome to CodeNameJessica

โœจ Welcome to CodeNameJessica! โœจ

๐Ÿ’ป Where tech meets community.

Hello, Guest! ๐Ÿ‘‹
You're just a few clicks away from joining an exclusive space for tech enthusiasts, problem-solvers, and lifelong learners like you.

๐Ÿ” Why Join?
By becoming a member of CodeNameJessica, youโ€™ll get access to:
โœ… In-depth discussions on Linux, Security, Server Administration, Programming, and more
โœ… Exclusive resources, tools, and scripts for IT professionals
โœ… A supportive community of like-minded individuals to share ideas, solve problems, and learn together
โœ… Project showcases, guides, and tutorials from our members
โœ… Personalized profiles and direct messaging to collaborate with other techies

๐ŸŒ Sign Up Now and Unlock Full Access!
As a guest, you're seeing just a glimpse of what we offer. Don't miss out on the complete experience! Create a free account today and start exploring everything CodeNameJessica has to offer.

by: Abhishek Prakash
Wed, 05 Mar 2025 20:45:06 +0530


The whereis command helps users locate the binary, source, and manual page files for a given command. And in this tutorial, I will walk you through practical examples to help you understand how to use whereis command.

Unlike other search commands like find that scan the entire file system, whereis searches predefined directories, making it faster and more efficient.

It is particularly useful for system administrators and developers to locate files related to commands without requiring root privileges.

whereis Command Syntax

To use any command to its maximum potential, it is important to know its syntax and that is why I'm starting this tutorial by introducing the syntax of the whereis command:

whereis [OPTIONS] FILE_NAME...

Here,

  • OPTIONS: Flags that modify the search behavior.
  • FILE_NAME: The name of the file or command to locate.

Now, let's take a look at available options of the whereis command:

Flag Description
-b Search only for binary files.
-s Search only for source files.
-m Search only for manual pages.
-u Search for unusual files (files missing one or more of binary, source, or manual).
-B Specify directories to search for binary files (must be followed by -f).
-S Specify directories to search for source files (must be followed by -f).
-M Specify directories to search for manual pages (must be followed by -f).
-f Terminate directory lists provided with -B, -S, or -M, signaling the start of file names.
-l Display directories that are searched by default.

To find all files (binary, source, and manual) related to a command, all you have to do is append the command name to the whereis command as shown here:

whereis command

For example, if I want to locate all files related to bash, then I would use the following:

whereis bash
Locate all files related to a command using whereis command

Here,

  • /usr/bin/bash: Path to the binary file.
  • /usr/share/man/man1/bash.1.gz: Path to the manual page.

2. Search for binary files only

To locate only the binary (executable) file of a command, use the -b flag along with the target command as shown here:

whereis -b command

If I want to search for the binary files for the ls command, then I would use the following:

whereis -b ls
Search for binary files only

3. Search for the manual page only

To locate only the manual page for a specific command, use the -m flag along with the targeted command as shown here:

whereis -m command

For example, if I want to search for the manual page location for the grep command, then I would use the following:

whereis -m grep
Search for manual page only using the whereis command

As you can see, it gave me two locations:

  • /usr/share/man/man1/grep.1.gz: A manual page which can be accessed through man grep command.
  • /usr/share/info/grep.info.gz: An info page that can be accessed through info grep command.

4. Search for source files only

To find only source code files associated with a command, use the -s flag along with the targeted command as shown here:

whereis -s command

For example, if I want to search source files for the gcc, then I would use the following:

whereis -s gcc

My system is fresh and I haven't installed any packages from the source so I was given a blank output.

5. Specify custom directories for searching

To limit your search to specific directories, use options like -B, -S, or -M. For example, if I want to limit my search to the /bin directory for the cp command, then I would use the following command:

whereis -b -B /bin -f cp
Limit search for specific directories using whereis command

Here,

  • -b: This flag tells whereis to search only for binary files (executables), ignoring source and manual files.
  • -B /bin: The -B flag specifies a custom directory (/bin in this case) where whereis should look for binary files. It also limits the search to the /bin directory instead of searching all default directories.
  • -f cp: Without -f, the whereis command would interpret cp as another directory.

6. Identify commands missing certain files (unusual files)

The whereis command can help you find commands that are missing one or more associated files (binary, source, or manual). This is particularly useful for troubleshooting or verifying file completeness.

For example, to search for commands in the /bin directory that is missing manual pages, you first have to change your directory to /bin and then use the -u flag to search for unusual files:

cd /bin
whereis -u -m *
Search for unsual files using whereis command

Wrapping Up...

This was a quick tutorial on how you can use the whereis command in Linux including practical examples and syntax. I hope you will find this guide helpful.

If you have any queries or suggestions, leave us a comment.

0 Comments

Recommended Comments

There are no comments to display.

Important Information

Terms of Use Privacy Policy Guidelines We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.