which
Quick Reference
Command Name:
which
Category:
system management
Platform:
linux
Basic Usage:
Common Use Cases
- 1
Command location
Find the location of executable files in the system
- 2
Path resolution
Determine which version of a command is being executed
- 3
Scripting
Use in shell scripts to dynamically locate commands
- 4
Troubleshooting
Diagnose issues with command execution
Syntax
which [OPTION]... COMMAND...
Options
Option | Description |
---|---|
-a, --all | Print all matching executables in PATH, not just the first |
-i, --read-alias | Read aliases from stdin, reporting matching ones on stdout (not in all versions) |
-s, --silent, --quiet | Silent mode, only return exit status (0 if found, 1 if not found) |
--skip-alias | Ignore option -i and skip alias processing |
--skip-functions | Ignore shell functions (not in all versions) |
--skip-dot | Skip directories in PATH that start with a dot |
--skip-tilde | Skip directories in PATH that start with a tilde and executables which reside in the HOME directory |
--show-dot | Don't skip directories in PATH that start with a dot |
--show-tilde | Convert HOME directory to a tilde in output |
--tty-only | Stop processing options on the right if not on tty |
-v, --version | Show version information |
-h, --help | Display help information |
Examples
How to Use These Examples
The examples below show common ways to use the which
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
which ls
Show the full path of the ls command.
which python
Find the location of the python interpreter.
which bash zsh sh
Find the full paths of multiple shells at once.
Advanced Examples:
which -a python
Show all instances of python in PATH, not just the first one.
which -a java | xargs ls -l
Find all instances of the Java command and show detailed file information for each.
PATH=/custom/path:/bin which program
Temporarily modify the PATH to check where a program would be found with a different PATH.