which tells you which file a command name actually runs. Learn how PATH decides the order, how to diagnose `command not found`, and why your own script is invisible until two things are true, by running the commands in a real terminal in your browser.
Updated: 2026-09-06
which command...
It searches PATH and prints the first file it finds.
$ which ls
/usr/bin/ls
When you type ls, the file that actually runs is /usr/bin/ls.
Several names at once work too.
$ which ls grep git
/usr/bin/ls
/usr/bin/grep
/usr/bin/git
Given a command name, the shell walks the directories in PATH from left to right.
$ echo $PATH
/usr/bin:/bin:/usr/local/bin
If the same name exists in more than one of them, the first hit wins.
$ which python3
/usr/bin/python3
This terminal also has a python3 in /usr/local/bin.
$ ls /usr/local/bin
python3
/usr/bin/python3 still wins, because /usr/bin comes first in PATH.
A newly installed version that never seems to be used is nearly always this.
Nothing found, nothing printed.
$ which nosuchcmd
Names built into the shell print nothing either.
$ which cd
cd is not a file at all; it is part of the shell.
So "which found nothing" does not mean "you cannot use it".
Say you dropped a script at ~/bin/backup.
$ which backup
Not found, for two separate reasons. First, without the execute permission it is not even a candidate.
$ chmod +x /home/user/bin/backup
$ which backup
Still nothing, because ~/bin is not on PATH.
$ export PATH=$PATH:/home/user/bin
$ echo $PATH
/usr/bin:/bin:/usr/local/bin:/home/user/bin
$ which backup
/home/user/bin/backup
Executable and on PATH: it takes both.
A PATH set with export lasts only for that terminal, so put it in .zshrc or .bashrc to keep it.
which is what you type to confirm you are running what you think you are running.
| Situation | What to type |
|---|---|
| Check which version is in use | which python3 |
| Confirm a tool is really installed | which docker |
| Diagnose command not found | which <name> and echo $PATH |
| Find where something was installed | which git |
Shell builtins never show up.
cd and export are not files, so which cannot answer for them.
PATH order decides the winner.
With two copies installed, the directory listed earlier in PATH wins.
When an upgrade seems to have no effect, read echo $PATH carefully.
Aliases are a different thing.
An alias such as ll is not a file on PATH, so which cannot see it.
Type alias when you want to know what an alias expands to.
webterm.appthis site
Advanced Terminal Commands
Learn commands for specific situations
learn.webterm.appa separate site

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course