Linux which command

Updated: 04/26/2017 by Computer Hope

About which

Locate the executable file associated with a given command.


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.

which syntax

which -a [filename] ...


-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.

which examples

which sh

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


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