which and whereis on Linux: Find Command Path and Man Pages

which command linux - custom-which-featured.png

which and whereis on Linux are top searches when a script says “command not found” or when two Python versions fight on PATH. which shows what your shell would run; whereis also lists man pages and source paths when installed.

See: environment variables,
bash aliases,
test.

which for PATH

Reports the first executable matching the name on PATH.

bashwhich
which python3
which nginx
which
PATH

whereis broader

Shows binary, source, and man page locations.

bashwhereis
whereis sshd
whereis -b grep
whereis
man

type and command -v

Shell builtins need type; scripts should use command -v for POSIX.

bashscripts
type cd
command -v curl
command -v
type

After install or update

Refresh command hash table or open a new shell when PATH changes.

TipCompare which python3 with readlink -f $(which python3) to see the real file behind a symlink.
hash -r
new shell

Quick Reference

  • Runtime binary: which name
  • Man/binary tree: whereis name
  • Scripts: command -v name

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.