Whereis Command in Linux and BSD with Examples

2 min


Here’s a beginner’s guide on understanding whereis command in Linux & BSD with several examples.

This article is part of the Linux command learning series.

whereis command

The whereis command is a command line program that helps you to find out the path or location of any binary executable, source file or manual page.

Before we show you how to use whereis command, let’s look at the syntax.

Syntax

Here’s the syntax for whereis command:

whereis [OPTIONS] FILE_NAME

The argument of whereis command is the program name or file name you want to search. The argument is mandatory.

By default, it searches for the program in the path defined in environment variables such as HOME, USER, SHELL, etc.

Let’s take a look at some examples.

Examples of whereis command in Linux and BSD

A simple example of whereis command is below where I am trying to search firefox. In the output below, you can see the list of paths containing firefox files or executables displayed.

$ whereis firefox

firefox: /usr/bin/firefox /usr/lib64/firefox /etc/firefox /usr/share/man/man1/firefox.1.gz
Simple example of whereis command in Linux
Simple example of whereis command in Linux

The command with option -l displays the list of paths where it searches. For example:

$ whereis -l

bin: /usr/bin
bin: /usr/sbin
bin: /usr/lib
bin: /usr/lib64
bin: /etc
bin: /usr/games
bin: /usr/local/bin
bin: /usr/local/sbin
bin: /usr/local/etc
bin: /usr/local/lib
bin: /usr/local/games

If the whereis command doesn’t find anything, it only shows the argument’s name. For example, if I search nano in Linux where is it not installed, it outputs the following:

$ whereis nano
nano:

You can always add multiple arguments if you want to search for more. For example below command searches for both bash and nano, and this is the output:

$ whereis bash nano

bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz
nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz

You can also search for specific file types, such as binaries, using -b option. The following command only tells you the binary paths of nano.

$ whereis -b nano

nano: /usr/bin/nano /usr/share/nano

Similarly, the -s option searches for source files, and the -m option searches for manual pages.

$ whereis -m nano

nano: /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz

You can also combine the above options for a more extensive search. For example, the following command searches for nano and firefox binary, manual pages and for bash, only manual pages.

$ whereis -bm nano firefox -m bash

nano: /usr/bin/nano /usr/share/nano /usr/share/man/man1/nano.1.gz /usr/share/info/nano.info.gz
firefox-m:
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz /usr/share/info/bash.info.gz

Here’s a summary of the options:

optiondescription
-bSearch only for binaries.
-mSearch only for manual sections.
-sSearch only for sources.
-uSearch for unusual entries. A file is said to be unusual if it does not have one entry of each requested type. Thus ‘whereis -m -u *’ asks for those files in the current directory which have no documentation.
-BChange or otherwise limit the places where whereis searches for binaries.
-MChange or otherwise limit the places where whereis searches for manual sections.
-SChange or otherwise limit the places where whereis searches for sources.
-fTerminate the last directory list and signals the start of file names, and must be used when any of the -B, -M, or -S options are used.

Closing Notes

I hope this article helps you to understand whereis command and its basics. You can also read the whereis man pages to learn more. Let me know if you have any questions.

This article is part of the Linux command learning series.


Arindam

Creator and author of debugpoint.com. Connect with me via Telegram, 𝕏 (Twitter), or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments