which - macOS
Overview
which – find the full path of a command
Syntax
which [-a] [-s] [-S] [-f] command ...
The which command searches the system’s $PATH environment variable for the first occurrence of each command specified on the command line and prints the full path of the command found.
Options/Flags
-a: Display all matching commands, instead of just the first one found.-s: Don’t display the matching commands; exit with a status of 0 if any of the commands are found in the$PATH, and 1 otherwise.-S: Silently ignore errors when searching for commands.-f: Ignore alias and shell functions when searching for commands.
Examples
- To find the full path of the 
lscommand: 
which ls
- To find all matching occurrences of the 
lscommand, including aliases and shell functions: 
which -a ls
- To check if the 
lscommand is in the$PATH, without printing its path: 
which -s ls
Common Issues
- If 
whichcannot find a command, it will exit with a non-zero status. You can use the-Soption to ignore this error. - If you get an “ambiguous” error message, it means that more than one command with the same name was found in the 
$PATH. You can use the-aoption to see all matching commands. 
Integration
The which command can be used in conjunction with other macOS commands to perform advanced tasks. For example, you could use it to create a custom command that adds a specific directory to the $PATH.
Related Commands
pathchkmanhelp