Linux / Unix: whereis Command Examples

by on January 13, 2014 · 4 comments· LAST UPDATED February 18, 2014

in , , ,

whereis command

I am a new Linux and Unix-like system command line user. How do I find and locate the binary, source, and manual page files for a given command?

You need to use the whereiscommand to find the source, binary, and manuals sections for specified commands or files.

whereis command details
DescriptionLocating command or program
Category
Difficulty
Root privilegesNo
Estimated completion time10m
Contents
A binary is nothing but an executable from of a command such as ls or program such as Gimp. Use this command to find out:

  1. The location of a binary file.
  2. The location of source code.
  3. The location of man page.

Purpose

Find the binary, source code and man page for specified program or command.

Syntax

The basic syntax is as follows:

whereis command

OR

whereis program

OR

whereis [options] program

OR

whereis -BMS directory -f command

whereis command examples

To find out the location of the executable, source code and man page for the date command, type:
$ whereis date
Sample outputs:

Animated gif 01: whereis command running on my Debian based server

Animated gif 01: whereis command running on my Debian based server

How do I only search for binary files?

Pass the -b option as follows:
$ whereis -b date

How do I only search for manual sections files?

Pass the -m option as follows:
$ whereis -m date

How do I only search for source code files?

Pass the -s option as follows:
$ whereis -s date

How do I only Search for unusual entries?

A file is said to be unusual if it does not have one entry of each requested type. Thus the following example, asks for those files in the current directory which have no documentation:
$ whereis -m -u *

How can I limit the searches for binaries to specific directories?

You can pass the following option to limit limit the places where whereis searches for files:

  • -B /path/to/dir : Limit the places where whereis searches for binaries.
  • -M /path/to/dir : Limit the places where whereis searches for manual sections.
  • -S /path/to/dir : Limit the places where whereis searches for sources.

You must pass the -f option when any of the -B, -M, or -S options are used. The -f option terminate the last directory list and signals the start of file names. In this example, limit search for binary files in /bin/ directory only for ls and gcc commands:
$ whereis -B /bin -f ls gcc
Sample outputs:

ls: /bin/ls /usr/share/man/man1/ls.1.gz
gcc:

There is no output for the gcc command since it is located in /usr/bin/ directory. To find all of the files in the /sbin/ directory that either are not documented in the /usr/man/man8 directory or do not have source in the /root/src directory, enter:
# cd /sbin
# whereis -u -M /usr/man/man8/ -S /root/src/ -f *

whereis command options

From the whereis(1) command man page:

OptionMeaning
-fDefine search scope.
-bSearch only binaries.
-BDefine binaries lookup path.
-mSearch only manual paths.
-MDefine man lookup path.
-sSearch only sources path.
-SDefine sources lookup path.
-uSearch from unusual enties.
-VOutput version information and exit.
-hDisplay this help and exit.
See also
CategoryList of Unix and Linux commands
File Managementcat
Network Utilitiesdighostip
Processes Managementbgchrootdisownfgjobskillkillallpwdxtimepidofpstree
Searchingwhereiswhich
User Informationgroupsidlastlastcommlognameuserswwhowhoamilidmembers

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 4 comments… read them below or add one }

1 Ivan February 19, 2014 at 11:19 am

Well done, guys ;)!

Reply

2 Jeremy Boden February 19, 2014 at 12:38 pm

Why not use the locate command for a list of files where you only know part of the name and nothing else?

Reply

3 jameslee February 19, 2014 at 3:21 pm

Thanks.its useful

Reply

4 Jose Damian Bazaga Ruiz March 9, 2014 at 8:54 pm

Helpful. Thank you for sharing this useful information about this command.

Reply

Leave a Comment

Tagged as: ,

Previous Faq:

Next Faq: