$linuxjunkies
>

which(1)

Locate a command in the user's PATH and display its full path.

UbuntuDebianFedoraArch

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

FlagWhat it does
-aPrint all matches in PATH, not just the first one
--skip-aliasSkip alias definitions when searching
--skip-functionsSkip shell function definitions when searching
--skip-builtinSkip shell built-in commands when searching
--skip-twhichSkip the internal hash table used to cache command locations

Examples

Show the full path to the python executable that will run

which python

List all python executables in PATH (e.g., python, python3 in different directories)

which -a python

Show paths for multiple commands at once

which ls cat grep

Returns nothing and exits with status 1 if command is not found

which nonexistent

Verify Node.js and npm are installed and show their locations

which node npm

Find all gcc installations if multiple versions exist in PATH

which -a gcc

Related commands