Open In App

whereis command in Linux with Examples

Last Updated : 03 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

whereis command is used to find the location of source/binary file of a command and manuals sections for a specified file in Linux system. If we compare whereis command with find command they will appear similar to each other as both can be used for the same purposes but whereis command produces the result more accurately by consuming less time comparatively. whereis doesn’t require any root privilege to execute in any RHEL/CentOS 7

The supplied names are first removed from leading pathname/directory components and any (single) trailing extension of the form .ext, for example, .c. Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the desired program in a list of standard Linux directories. 

Points to be kept on mind while using whereis command:

  • Since whereis command uses chdir(change directory 2V) to give you the result in fastest possible way, the pathnames given with the -M, -S, or -B must be full and well defined i.e. they must begin with a `/‘ and should be a valid path that exist in the system’s directories, else it exits without any valid result.
  • whereis command has a hard-coded(code which is not dynamic and changes with specification) path, so you may not always find what you’re looking for.

Syntax:

whereis [options] filename...

Example 1: Let’s say, we want to find the location of apropos command then we need to execute the following command in the terminal: 

 

Example 2: To find the location of lshw command.

  

Options:

  • -b : This option is used when we only want to search for binaries. 
    Example: To locate binary of a Linux command let’s say gunzip. 
  • -m : This option is used when we only want to search for manual sections. Example: To locate man page of false command.
  • -s : This option is used when we only want to search for sources.
  • -u: This option search for unusual entries. A source file or a binary file is said to be unusual if it does not have any existence in system as per [-bmsu] described along with “–u”. Thus `whereis -m -u *‘ asks for those files in the current directory which have unusual entries. Example: To display the files in the current directory which have no documentation file. 
  • -B : This option is used to change or otherwise limit the places where whereis searches for binaries. Example: To locate binary of lesspipe in the path, /bin
  • -M : This option is used to change or otherwise limit the places where whereis searches for manual sections. Example: To check man page of intro that is only in a specific location i.e. /usr/share/man/man1.
     
  • -S : This option is used to change or otherwise limit the places where whereis searches for sources. Example: To Find all files in /usr/bin which are not documented in /usr/man/man1 with source in /usr/src.
     
  • -f : This option simply terminate the last directory list and signals the start of file names. This must be used when any of the -B, -M, or -S options are used.
  • -V: Displays version information and exit.
     
  • -h: Displays this help and exit.
     

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads