The whereis command helps you to find the source files, binary files, and manuals sections for Linux commands. It locates the desired program in the standard Linux places, and in the places specified by $PATH and $MANPATH. In this tutorial, we will learn how to use the whereis command in Linux.
Let’s get started.
How to use the whereis command in Linux?
To use the whereis command in Linux you just need to type whereis with a proper argument. The argument can be any command you need to get the source file, binary file, and manuals section for. Let’s try out whereis on whereis itself.
whereis: /usr/bin/whereis /usr/share/man/man1/whereis.1.gz
- /usr/bin/whereis is the path to the binary file.
- /usr/share/man/man1/whereis.1.gz is the path to the man page.
whereis was not able to find the source file in the list of directories it searches through.
You can get the list of locations whereis is searching in. To get the list of effective lookup paths that whereis is using, use :
Whereis command also gives you the options to display only the source file or the binary file or the manuals section. Let’s look at this next.
Options available along with whereis
The options available along with the Whereis command are as follows :
- s: search only for the source files.
- b: search only for the binary files.
- m: search only for manuals.
1. Search only binary files using whereis
If you don’t want the manual files or the source files, you can use the -b flag to get only the binary files here.
whereis -b whereis
2. Search only manual files with whereis
Want to only check the location of the manuals? The -m flag is what you need
whereis -m whereis
Providing more the one command to whereis
You can provide more than one commands as arguments along with the whereis command. So when you need to find the source of many commands at once, you don’t have to run the command over and over again.
whereis whereis bash
whereis: /usr/bin/whereis /usr/share/man/man1/whereis.1.gz bash: /usr/bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz
The output for two commands is displayed in two separate lines.
Find commands with unusual entries
You can use the whereis command to find files with unusual entries. You can find commands with missing documentation or more than one documentation using:
whereis -m -u *
symlink: /usr/share/man/man2/symlink.2.gz /usr/share/man/man7/symlink.7.gz
Whereis searches for these unusual entries in the list of its effective lookup paths.
cd /bin whereis -m -u *
You can also find commands with unusual entires in a particular directory. To use whereis in a particular directory you can use the following syntax.
whereis -B [path to directory] -f [command]
whereis -B /usr/bin/ -f bash
bash: /usr/share/man/man1/bash.1.gz /usr/bin/bash
This tutorial was about whereis command in Linux. We learned how this command can be used to find the source, binary, and manuals sections for Linux commands.