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_nameis the name of the command or program you want to locate.optionsmodify 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
whereisto search all directories; it only searches standard system paths. - Confusing
whereiswithwhich, 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:
| Option | Description |
|---|---|
| -b | Search only for binaries |
| -m | Search only for manual files |
| -s | Search only for source files |
| -u | Search 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.