Linux command list

which command: find out which program actually runs

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying which. Nothing here can touch your real files.
user@webterm:~/project$
 

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

Syntax

which command...

It searches PATH and prints the first file it finds.

Try it first

$ 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.

When nothing is printed

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".

When your own script is invisible

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.

When you actually reach for it

which is what you type to confirm you are running what you think you are running.

SituationWhat to type
Check which version is in usewhich python3
Confirm a tool is really installedwhich docker
Diagnose command not foundwhich <name> and echo $PATH
Find where something was installedwhich git

Things that trip people up

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.

Practise it hands-on

webterm.appthis site

  • Advanced Terminal Commands

    Learn commands for specific situations

    Try the tutorial

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

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

Related commands

man / echo / chmod / ls

Frequently asked questions

What does which tell me?
The file that will actually run when you type that name. When several copies of a program exist, it says which one wins.
Why does it print nothing?
Either nothing matched on your PATH, or the name is built into the shell, like `cd`. Builtins have no file, so which has nothing to point at.
What if the same command exists twice?
PATH is searched left to right and the first match wins. When a version you just installed does not seem to take effect, suspect the order of PATH.
My own script says command not found.
It needs the execute permission (`chmod +x`) and its directory has to be on PATH. One without the other is not enough.
When do I use which instead of man?
`which` answers where, `man` answers how. Version confusion is a which question; options are a man question.