Name

which

Synopsis

    which [options] [commands]

List which files are executed if the named commands are run as a command. which reads the user’s .cshrc file (using the source built-in command), checking aliases and searching the path variable. Users of the Bourne or Korn shells can use the built-in type command as an alternative. (See type, Chapters 4 and 5.)

GNU/Linux Options

-a, --all

Print all matches, not just the first.

-i, --read-alias

Read aliases from standard input and write matches to standard output. Useful for using an alias for which.

--read-functions

Read shell functions from standard input and report matches to standard output. Useful for also using a shell function for which itself.

--show-dot

If a matching command is found in a directory that starts with a dot, print ./cmdname instead of the full pathname.

--show-tilde

Print a tilde (~) to indicate the user’s home directory. Ignored if the user is root.

--skip-alias

Ignore --read-alias if present. Useful for finding normal binaries while using --read-alias in an alias for which.

--skip-dot

Skip directories that start with a dot.

--skip-functions

Ignore --read-functions if present. Useful when searching for normal binaries while using --read-functions in an alias or function for which.

--skip-tilde

Skip directories that start with a tilde (~) and executables in $HOME.

--tty-only

Stop processing options on the right if not on a terminal.

-v, -V, --version

Print version information and then exit.

Example

$ which file ls /usr/bin/file ...

Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.