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.

  • Description
  • Syntax
  • Exit status
  • Examples
  • Related commands
  • Linux commands help

which does not follow symbolic links.

Syntax

which -a [filename] …

Options

Exit status

which returns the following value, depending on what occurred:

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.