which(1)
Locate a command in the user's PATH and display its full path.
Synopsis
which [-a] [--skip-alias] [--skip-functions] [--skip-builtin] [--skip-twhich] COMMAND [COMMAND]...Description
which searches the directories in the PATH environment variable and returns the absolute path of the executable file that would run if you typed the command name.
It's useful for determining which version of a program will execute, troubleshooting PATH issues, or verifying that a command is installed and accessible.
Note that which may behave differently depending on whether you're using the shell built-in version or the standalone binary; most systems use the standalone /usr/bin/which.
Common options
| Flag | What it does |
|---|---|
-a | Print all matches in PATH, not just the first one |
--skip-alias | Skip alias definitions when searching |
--skip-functions | Skip shell function definitions when searching |
--skip-builtin | Skip shell built-in commands when searching |
--skip-twhich | Skip the internal hash table used to cache command locations |
Examples
Show the full path to the python executable that will run
which pythonList all python executables in PATH (e.g., python, python3 in different directories)
which -a pythonShow paths for multiple commands at once
which ls cat grepReturns nothing and exits with status 1 if command is not found
which nonexistentVerify Node.js and npm are installed and show their locations
which node npmFind all gcc installations if multiple versions exist in PATH
which -a gcc