WHICH(1) User Commands WHICH(1)
NAME
which - locate a program file in the user's path
SYNOPSIS
which [
-as]
command ...DESCRIPTION
The
which utility takes a list of command names and searches the path
for each executable file that would be run had these commands actually
been invoked.
Some shells may provide a built-in
which command which is similar or
identical to this utility.
OPTIONS
The following options are available:
-a List all instances of executables found (instead of just
the first one of each).
-s No output, just return 0 if all of the executables are
found, or 1 if some were not found.
OPERANDS
The following operands are supported:
command The name of a command to be located.
ENVIRONMENT
See
environ(7) for descriptions of the following environment variables
that affect the execution of
which: PATH.
EXIT STATUS
The following exit values are returned:
0 All of the provided operands were found in the path and would
be executed if the commands were invoked.
1 One or more of the provided operands was not found in the path
or would not be executed if the commands were invoked, or an
error occurred.
2 Invalid command line options were specified.
EXAMPLES
Example 1 Locate the `ls' and `cp' commands.
$ /usr/bin/which ls cp
/usr/bin/ls
/usr/bin/cp
Example 2 Use a specific PATH and show all occurrences.
$ PATH=/usr/bin:/usr/has/bin /usr/bin/which -a edit
/usr/bin/edit
/usr/has/bin/edit
Example 3 Executable reported multiple times.
If PATH contains repeated components, the same executable can be
reported more than once:
$ PATH=/usr/bin:/usr/bin /usr/bin/which -a ls
/usr/bin/ls
/usr/bin/ls
Example 4 Do not show output.
Just exit with an appropriate return code:
$ /usr/bin/which -s ls cp
$ echo $?
0
$ /usr/bin/which -s fakecommand
$ echo $?
1
INTERFACE STABILITY
The command line interface of
which is
Committed. The output of
which is
Committed.
SEE ALSO
find(1),
environ(7)illumos March 15, 2023 illumos