The which command
The which command shows the full path of the program a command runs…
The which command shows the full path of the program a command runs, by searching the folders in your PATH.
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.
Usage
which [-a] COMMAND...
Show where a command’s program lives. Prints the path of the program that runs for each command, by searching the folders in $PATH in order. Builtins such as cd have no program, so which prints nothing for them (type tells you about those). If you change $PATH, which shows the effect.
How to use which
Find a program
which ls/usr/bin/ls
which tar sed awk/usr/bin/tar /usr/bin/sed /usr/bin/awk
Why nothing is printed for cd
cd is built into the shell, so there is no program to find. Use type for builtins and aliases.
type cdcd is a shell builtin
Options
| -a | every match, not just the first |
|---|
More examples
echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Questions about which
Why does which print nothing?
The command isn’t a program in any folder of your PATH: it may be a shell builtin (try type name), an alias, or not installed.
Related commands
Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.