How to use whereis command
In Linux, there is one really useful command: whereis, it helps you locate the binary, source and manual page files for a command.
Let’s start with a quick example:
$ whereis apache2
apache2: /usr/sbin/apache2 /usr/lib/apache2 /etc/apache2 /usr/share/apache2 /usr/share/man/man8/apache2.8.gz
In this way you can simply find the location for the absolute path names used by the apache2 command. You can notice that the first result: /usr/sbin/apache2 is the actual path for the command and all of the next results are either source or manual files.
If you want to check where are only the manual and infos, here comes the -m option, it only searches for manual and infos about the command:
$ whereis -m apache2
apache2: /usr/share/man/man8/apache2.8.gz
Another useful option is -b it shows only the binaries, or said in another way – where files of the command itself are available in the particular system:
$ whereis -b apache2
apache2: /usr/sbin/apache2 /usr/lib/apache2 /etc/apache2 /usr/share/apache2
The same thing you can do with -s, it searches only for source files.
With -l option you can see all of the paths where whereis is looking for results (only partial output is shown). If none of -B, -M, or -S is specified, it shows the hard-coded paths in the system that the command was able to find:
$ whereis -l
bin: /usr/bin
bin: /usr/sbin
bin: /usr/lib
bin: /bin
bin: /sbin
bin: /etc
bin: /lib
bin: /lib64
bin: /usr/games
bin: /usr/local/bin
bin: /usr/local/sbin
bin: /usr/local/etc
bin: /usr/local/lib
bin: /usr/local/games
bin: /usr/include
bin: /usr/local
bin: /usr/share
man: /usr/share/man/sl
In case you want to specify in which directory to search in whereis , you can use -B with an argument. For example:
$ whereis -B /usr/share/ -f apache2
apache2: /usr/share/man/man8/apache2.8.gz /usr/share/apache2
Along with -B we have used and the -f option, it must be added when –B, -M, or -S is specified.
All of the -B (searches for binaries), -M (searches for manuals and documentation in Info format), or -S (searches for sources) are used to limit the search of whereis in a different way. The common between them is the fact that they limit by whitespace-separated list of directories. Whitespace most commonly depends on the character set being used – some of them are: “U+0020 – SPACE”, “U+2008 PUNCTUATION SPACE”, “U+2009 THIN SPACE”.