man.lsPlain-English help for Unix commands

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 formWhat it does
-aPrint every match on your PATH, not only the first. Works on macOS and on Linux (GNU)
-sOn 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

Find where a command lives
which ls
List every copy on the PATH
which -a sh
Check several commands at once
which sh ls cat
Use it in a script to test that a tool exists
which sh > /dev/null && echo installed
installed

Notes

See also

Last reviewed 2026-10-07.