When to use which
Use which as a quick executable-path lookup where its implementation is known. For understanding exactly what the interactive shell will run, inspect aliases, functions and builtins with the shell's own resolution tools.
Syntax
which [PARAMETERS] NAME…Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Find SSH-client
which sshAn executable match is searched along the configured path.
Show all matching Python executables
which -a python3Multiple matching executable paths are requested if the implementation supports the option.
Compare with name resolution in Bash
type -a sshThe shell's own command resolver provides a broader comparison.
Notes and limitations
- which typically looks for external files and does not fully reflect aliases, functions, and built-in commands.
- To find out the actual behavior of the shell, use type; in portable scripts - command -v.
Common questions and troubleshooting
Why does which find a different command from my shell?
Aliases, functions, builtins and cached lookups can affect shell resolution. Inspect type and the active command search path.
Does a returned path prove the program is trustworthy?
No. It only identifies a path according to the search. Verify ownership, provenance and expected version when trust matters.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man which.