0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use whereis Command in Linux: Syntax and Examples

Use the whereis command in Linux to find the location of a program's binary, source, and manual files. The basic syntax is whereis [options] program_name, which helps you quickly locate files related to a command.
📐

Syntax

The basic syntax of the whereis command is:

  • whereis [options] program_name

Here:

  • program_name is the name of the command or program you want to locate.
  • options modify the search behavior, like limiting to binaries, sources, or manuals.
bash
whereis [options] program_name
💻

Example

This example shows how to find the locations of the ls command's binary, source, and manual files using whereis.

bash
whereis ls
Output
ls: /bin/ls /usr/share/man/man1/ls.1.gz
⚠️

Common Pitfalls

Common mistakes when using whereis include:

  • Typing the program name incorrectly, which returns no results.
  • Expecting whereis to search all directories; it only searches standard system paths.
  • Confusing whereis with which, which only shows the binary path.
bash
whereis notaprogram
# No output or just the program name

whereis ls
# Correct usage shows locations
Output
notaprogram: ls: /bin/ls /usr/share/man/man1/ls.1.gz
📊

Quick Reference

Here is a quick reference for common whereis options:

OptionDescription
-bSearch only for binaries
-mSearch only for manual files
-sSearch only for source files
-uSearch for unusual entries (files not in standard locations)
-B Specify directories to search for binaries
-M Specify directories to search for manuals
-S Specify directories to search for sources

Key Takeaways

Use whereis program_name to find binary, source, and manual file locations.
The command searches standard system directories, not the entire filesystem.
Use options like -b, -m, and -s to narrow the search.
Check spelling of the program name to avoid empty results.
Remember whereis differs from which, which only shows the binary path.