which (Show if and where a command lives in your path)

First, let’s review the concept of a PATH. The PATH is defined in your shell profile (.bash_rc or .zshrc) and looks like a variable $PATH. It is typically to see a $PATH string in here that contains several directories separated by colons (:), like so:

This tells your terminal (your shell prompt), where to look for commands you type. Specifically, when you type a shell prompt, it looks in the first location first, then if it doesn’t find a corresponding shell command, it then looks into the next location, and so on.

You might be using a terminal command you never used before— like python, or openssl or node. You will often want to know if and where the given executable lives in your system (in your path directories, as explained above).

For this, you use the which command, like so:

which pyhon

Here, we ask the operating system if and where Python is installed.

which brew

Here, we ask the operating system if and where the Node executable is installed.

which node

Here, we ask the operating system if and where the Node executable is installed.

If the shell prompt doesn’t find the thing specified, it says: “___ not found”