which
Processes and system
Usage
which [-a] <name>Searches PATH and tells you where the executable of that name lives; because it looks only at PATH it lies about aliases, functions and shell builtins, and the honest answer comes from `type -a` or `command -v`.
Common flags
| Flag | Meaning |
|---|---|
| -a | Show every match in PATH, not just the first one. |
| <name> <name> | Several names at once; the exit status is nonzero if any is missing. |
| -s | Print nothing, just set the exit status (BSD/macOS). |
Examples
which -a python3Spot a second python3 earlier in PATH than the one you expected.
command -v node || echo missingThe portable check to use in scripts.
What is running and what is eating the machine. Identifying it comes before killing it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does which do?
Searches PATH and tells you where the executable of that name lives; because it looks only at PATH it lies about aliases, functions and shell builtins, and the honest answer comes from `type -a` or `command -v`.
Q. How do I type it?
which [-a] <name> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
3 are listed here; the full set is in man which. This command sits under Processes and system.
Related commands
man page: man which