Linux whereis Command

Locate Binary, Source, and Manual Pages for Commands

Command Overview

whereis locates the binary, source code, and manual page files for specified commands. It searches a fixed set of system directories rather than the entire filesystem, making it much faster than find. It's particularly useful for finding where programs are installed and locating their documentation.

whereis vs Similar Commands

Command Purpose Search Method Speed
whereis Find binaries, sources, man pages Standard directories only Fast
which Find executable in PATH $PATH environment variable Very Fast
locate Find any file by name Pre-built database Very Fast
find Find any file with criteria Real-time filesystem scan Slow
type Identify command type Shell builtins & PATH Instant
Key Feature: whereis searches standard system directories like /bin, /sbin, /usr/bin, /usr/local/bin, /usr/share/man, etc. It won't find programs installed in non-standard locations.

Example 1: Basic Search for Command

whereis python3
python3: /usr/bin/python3 /usr/bin/python3.10 /usr/lib/python3 /usr/lib/python3.10 /etc/python3 /etc/python3.10 /usr/share/man/man1/python3.1.gz
Explanation:

Locates all files related to python3 including binaries, libraries, and manual pages.

  • /usr/bin/python3: Main executable binary
  • /usr/bin/python3.10: Version-specific binary
  • /usr/lib/python3: Library directories
  • /etc/python3: Configuration directories
  • /usr/share/man/...: Manual page file
  • Use case: Quick overview of where Python is installed

Example 2: Show Only Binary Locations

whereis -b gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/gcc-11
Explanation:

Displays only binary file locations, excluding manual pages and source code.

  • -b option: Search only for binaries
  • /usr/bin/gcc: Main GCC executable
  • /usr/lib/gcc: GCC library directory
  • /usr/bin/gcc-11: Version-specific compiler
  • Use case: Find where a program is installed without extra noise

Example 3: Show Only Manual Page Locations

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

Displays only manual page file locations for the ls command.

  • -m option: Search only for manual pages
  • .gz extension: Manual pages are typically compressed
  • man1 directory: Section 1 is for user commands
  • Use case: Verify documentation is installed, find man page location
Tip: If whereis -m returns nothing, the manual page isn't installed. Install with package manager, e.g., apt install man-db

Example 4: Show Only Source Code Locations

whereis -s bash
bash:
Explanation:

Searches for bash source code files (typically returns nothing unless source is installed).

  • -s option: Search only for source files
  • Empty result: Source code not installed (common for binaries)
  • Source locations: Usually /usr/src if installed
  • Use case: Verify if source code is available locally
Note: Most Linux distributions don't install source code by default. Use apt source package-name or similar to download source.

Example 5: Search Multiple Commands

whereis bash zsh fish
bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz zsh: /bin/zsh /etc/zsh /usr/share/man/man1/zsh.1.gz fish: /usr/bin/fish /etc/fish /usr/share/man/man1/fish.1.gz
Explanation:

Searches for multiple shell programs simultaneously.

  • Multiple arguments: Space-separated command names
  • Efficient: One command instead of three separate ones
  • Comparison: See which shells are installed
  • Each line: Shows results for one command
  • Use case: Compare installations across similar programs

Example 6: Limit Search to Specific Binary Directory

whereis -B /usr/local/bin -f python3
python3: /usr/local/bin/python3
Explanation:

Restricts binary search to only /usr/local/bin directory.

  • -B option: Specify custom binary search directories
  • -f flag: Required separator before file names
  • Custom path: /usr/local/bin (user-installed software)
  • Result: Shows only manually-installed Python version
  • Use case: Find specific installation when multiple versions exist

Example 7: Limit Search to Specific Manual Directory

whereis -M /usr/local/man -f custom_tool
custom_tool: /usr/local/man/man1/custom_tool.1
Explanation:

Searches for manual pages only in /usr/local/man directory.

  • -M option: Specify custom manual page directories
  • /usr/local/man: Manual pages for locally-installed software
  • -f separator: Marks end of directory list
  • Use case: Find documentation for custom-built tools

Example 8: Custom Source Directory Search

whereis -S /usr/local/src /home/user/src -f myproject
myproject: /home/user/src/myproject
Explanation:

Searches for source code in specified custom directories.

  • -S option: Specify custom source directories
  • Multiple paths: Can list several directories to search
  • /home/user/src: Personal source code directory
  • -f separator: Ends directory list, starts file names
  • Use case: Locate development projects in custom locations

Example 9: Unusual Search - Only Show Binaries Without Man Pages

whereis -b docker-compose | grep -q "/usr/share/man" || echo "No man page found"
docker-compose: /usr/bin/docker-compose /usr/libexec/docker/cli-plugins/docker-compose
Explanation:

Checks if a binary exists but lacks manual page documentation.

  • -b option: Show only binaries
  • Pipeline: Combined with grep to check for man pages
  • Use case: Identify commands missing documentation
  • Script-friendly: Can automate documentation checks

Example 10: Comprehensive Search with All Options

whereis -bms nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/man/man8/nginx.8.gz
Explanation:

Explicitly shows binaries, manual pages, and source (though -bms is redundant since default shows all).

  • -b: Binaries (/usr/sbin/nginx)
  • -m: Manual pages (/usr/share/man/...)
  • -s: Source (none found for nginx)
  • Combined options: All three types in one search
  • Note: Default behavior already searches all types
  • Use case: Explicit documentation of what you're searching for
Best Practice: The default whereis command (without options) already searches for all types. Use specific options (-b, -m, -s) only when you want to filter results.

Additional Information

Command Options

Standard Search Directories

Binaries: /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin /usr/games, /opt/*/bin Manual Pages: /usr/share/man/*, /usr/local/share/man/* /usr/man/*, /opt/*/man/* Source Code: /usr/src/*, /usr/local/src/*

Related Commands

Common Use Cases

Differences from which

# which: Shows only executable in PATH $ which python3 /usr/bin/python3 # whereis: Shows all related files $ whereis python3 python3: /usr/bin/python3 /usr/bin/python3.10 /usr/lib/python3 /etc/python3 /usr/share/man/man1/python3.1.gz # Summary: - which: Faster, PATH-only, first match - whereis: More comprehensive, standard dirs, all matches

Best Practices

Troubleshooting

# Command not found $ whereis mycustomscript mycustomscript: # Reasons: Not in standard directories, use which or find instead # Find where whereis searches (system-dependent) $ whereis -l # Shows search paths on some systems # Alternative for custom locations $ find /opt -name "mycustomscript" -type f 2>/dev/null # Check if in PATH $ which mycustomscript # Most comprehensive search $ locate mycustomscript

Example: Script to Check Command Installation

#!/bin/bash # check_install.sh - Verify command installation completeness COMMAND=$1 echo "Checking installation of: $COMMAND" echo "==================================" # Check binary BINARY=$(whereis -b $COMMAND | cut -d: -f2) if [ -n "$BINARY" ]; then echo "✓ Binary found:$BINARY" else echo "✗ Binary NOT found" fi # Check manual page MAN=$(whereis -m $COMMAND | cut -d: -f2) if [ -n "$MAN" ]; then echo "✓ Manual page found:$MAN" else echo "✗ Manual page NOT found" fi # Check source SOURCE=$(whereis -s $COMMAND | cut -d: -f2) if [ -n "$SOURCE" ]; then echo "✓ Source found:$SOURCE" else echo "○ Source not installed (normal)" fi

Example: Find Commands Missing Documentation

#!/bin/bash # find_undocumented.sh for cmd in /usr/bin/*; do cmdname=$(basename "$cmd") if ! whereis -m "$cmdname" | grep -q "/usr/share/man"; then echo "$cmdname has no man page" fi done

Example: Comparing Installed Editors

$ whereis vim emacs nano vi vim: /usr/bin/vim /usr/bin/vim.basic /usr/bin/vim.tiny /etc/vim /usr/share/man/man1/vim.1.gz emacs: /usr/bin/emacs /usr/share/man/man1/emacs.1.gz nano: /bin/nano /usr/share/man/man1/nano.1.gz vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz # Quick inventory of available text editors

Understanding Manual Page Sections

Manual Page Sections:
  • man1: User commands (executable programs or shell commands)
  • man2: System calls (functions provided by kernel)
  • man3: Library calls (functions within program libraries)
  • man4: Special files (usually found in /dev)
  • man5: File formats and conventions
  • man6: Games and screensavers
  • man7: Miscellaneous (macro packages, conventions)
  • man8: System administration commands

Limitations of whereis

Pro Tip: Create an alias for comprehensive command lookup:
alias findcmd='f(){ echo "whereis:"; whereis "$1"; echo "which:"; which "$1"; echo "type:"; type "$1"; }; f' # Usage: findcmd python3 # Shows results from whereis, which, and type together