which Show where a command is located
Looks through the folders in your PATH and prints the full path of the program that would run if you typed the name. Use it to find out which copy of a tool you are using, or whether it is installed at all.
Synopsis
which [-a] command...
Common options
| Option or form | What it does |
|---|---|
-a | Print every match on your PATH, not only the first. Works on macOS and on Linux (GNU) |
-s | On macOS, print nothing and only set the exit status. Not available in every Linux version |
command... | One or more program names to look up. Each is searched for along your PATH, in order. Not a flag |
Examples
which ls
which -a sh
which sh ls cat
which sh > /dev/null && echo installed
installed
Notes
- which only finds programs (executable files) on your PATH. It does not know about shell built-ins or aliases, so it can miss or misreport commands such as cd.
- To see how the shell would really run a name, including aliases, functions and built-ins, use type, for example type cd. In bash, type -a shows every kind of match.
- If a command is not found, which prints nothing or an error and exits with a non-zero status. The exact message differs between systems.
- Different systems ship different versions of which. Output wording and some options are not the same on macOS and Linux, so keep scripts to the plain form.
- If which shows a different path than you expected, an earlier folder on your PATH is winning. Print the order with echo $PATH.
See also
Last reviewed 2026-10-07.