whereis Command in Linux with Examples

The whereis command in Linux locates the binary, source, and manual page files for a given command or file. It is a very useful command for finding files on your system, especially if you don’t know where they are located.

The supplied names are first stripped of leading pathname 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 places.

Syntax:

whereis [Options] filename ...

The file name is the name of the command or file that you want to locate.

Options:

  • -b: Only search for binary files.
  • -m: Only search for manual sections.
  • -s: Only search for source files.
  • -u: Search for unusual files. A file is said to be unusual if it does not have one entry of each requested type. For example, whereis -m -u * asks for those files in the current directory which have no documentation.
  • -B: Change the default binary search path.
  • -M: Change the default manual page search path.
  • -S: Change the default source search path.
  • -f: Terminate the last directory list and signal the start of file names. It must be used when any of the -B, -M, or -S options are used.

whereis Command Examples

advertisement
advertisement

Example 1: Find the location of the ls command

$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz

This output shows that the binary file for the ls command is located at /bin/ls, the manual page file is located at /usr/share/man/man1/ls.1.gz, and the manual page file for the ls command in a different format is located at /usr/share/man/man1p/ls.1p.gz.

Example 2: Find the location of the executable for the ls command

$ whereis -b ls
ls: /bin/ls

This output shows that the binary file for the ls command is located at /bin/ls.

Example 3: Change the search location of the whereis command

$ whereis -u -B /tmp -f lsmk
lsmk: /tmp/lsmk

This output shows that the executable file for the lsmk command is located at “/tmp/lsmk”.

advertisement
  • The -u option tells the whereis command to search for unusual files, which are files that do not have a manual page or source code file.
  • The -B option tells the whereis command to search for the executable file in the /tmp directory.
  • The -f option tells the whereis command to end the list of directories and start the list of file names.

Example 4: Locate man pages for the whereis command using the -m option

$ whereis -m whereis
whereis: /usr/share/man/man1/whereis.1.gz

This output shows that the manual page file for the whereis command is located at /usr/share/man/man1/whereis.1.gz.

Example 5: Find all files in /usr/bin

Find all files in /usr/bin which are not documented in /usr/man/man1 with source in /usr/src:

advertisement
$ whereis -u -M /usr/man/man1 -S /usr/src -f *"

This output shows all files in the /usr/bin directory that do not have a manual page in the /usr/man/man1 directory and have source code in the /usr/src directory.

  • The -u option tells the whereis command to search for unusual files, which are files that do not have a man page or source code file.
  • The -M option tells the whereis command to search for man pages in the /usr/man/man1 directory.
  • The -S option tells the whereis command to search for source code files in the /usr/src directory.
  • The -f option tells the whereis command to end the list of directories and start the list of file names.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.