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.
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
-b - Search only for binaries
-m - Search only for manual pages
-s - Search only for source code
-u - Search for unusual entries (files with zero or multiple matches)
-B list - Limit binary search to directories in list
-M list - Limit manual page search to directories in list
-S list - Limit source code search to directories in list
-f - Terminate directory list (required before file names with -B/-M/-S)
-l - Display list of directories searched (varies by system)
Find program location: Quick check where software is installed
Verify installation: Confirm binaries and docs are present
Multiple versions: Identify all installed versions of a program
Documentation check: Verify manual pages are installed
Development: Locate source code directories
System audit: Inventory installed software locations
Troubleshooting: Find conflicting installations
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
Use whereis for comprehensive system file location
Use which to find which executable will run
Combine with ls -l to check file details and symlinks
Use -b option to avoid clutter when only binaries matter
Check multiple related commands together for comparison
Remember: whereis won't find files in non-standard locations
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
Only searches predetermined standard directories
Won't find programs in /opt/custom or ~/bin
Doesn't search $PATH variable (use which for that)
May not find recently installed software in unusual locations
Source code search rarely returns results (sources not typically installed)
Can't search for partial names or use wildcards
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