which

Locate a program file (UNIX)

Syntax:

which [-afLls] program...

Options:

-a
Find all occurrences of program in PATH.
-f
Display the full pathname.
-L
Display the long format (as in ls -l ) for each program found, displaying link information if the file is a symlink.
-l
("el") Display the long format (as in ls -l ) for each program found.
-s
Search for shared objects in the directories identified by the LD_LIBRARY_PATH environment variable and the _CS_LIBPATH configuration string.

Description:

The which utility searches for the specified programs. By default, which searches the directories listed by your PATH environment variable, but if you specify the -s option, it searches the directories specified by LD_LIBRARY_PATH and _CS_LIBPATH.

The Korn shell has a builtin whence command that's similar to the which utility but also tells you if the given command is a reserved word, alias, builtin command, and so on. For more information, see the entry for ksh.

Examples:

Display the full pathname and long status for all versions of the ls utility found in PATH:

which -alf ls

Display the pathname for the which utility:

which which

Environment variables:

PATH
A colon-separated list of directories to search for executables.
LD_LIBRARY_PATH
A colon-separated list of directories to search for shared libraries.

Exit status:

0
All input files were found.
>0
An error occurred.

Last modified: 2013-12-21



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus