Linux which command

Updated: 11/06/2021 by Computer Hope
which command

On Unix-like operating systems, the which command locates the executable file associated with a given command.

This page covers the Linux version of which.

Description

which returns the pathnames of the files (or links) which would be executed in the current environment, had the filename (or filenames) been given as a command (or commands) in a strictly POSIX-conformant shell. It does this by searching the paths in the PATH environment variable for executable files matching the names of the arguments.

which does not follow symbolic links.

Syntax

which -a [filename] ...

Options

-a Print all matching pathnames of each matching filename.

Exit status

which returns the following value, depending on what occurred:

0 All filenames were found, and all were executable.
1 One or more filenames were not found, or were not executable.
2 An invalid option was specified.

Examples

which sh

Locates the pathname of the file which would run if the sh command were executed. On most systems, this will output:

/bin/sh

find — Find files within a directory hierarchy.
whereis — Locate the binary, source, and manual page files for a command.