1. Introduction to Commands
which The function of the (which) command is to search for the location of a system command in the path specified by the PATH variable and return the first search result. In other words, you can use the which command to see if a system command exists and where the command is executed.
2. Usage
/usr/bin/which [options] [--] COMMAND [...]
3. Options
--version,-[VV "display version information --help, displaying Help information --skip-dot Skip Directories in PATH that s Tart with a dot. --skip-tilde Skip Directories in PATH that Start with a tilde. --show-dot don " t expand a dot to current Dir Ectory in output. --show-tilde Output A tilde for HOME directory for
non-root. --tty-only Stop processing options on the right if Not on TTY. --all,-a finds all matches instead of the first
--read-alias,-I read list of aliases from stdin. --skip-alias Ignore option--read-alias; Don't read stdin. --read-functions Read Shell functions from stdin. --skip-functions Ignore option--read-functions; Don't read stdin.
4. Example 1: View the default JDK
which Java/usr/bin/java
Example 2:which find the directory, the value of the PATH variable
Echo $PATH/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin :/root/bin
Example 3: The specific alias information is listed when you look up a command that has an alias
which which which='alias |/usr/bin/which--tty-only--read-alias--SHOW-DOT--show-tilde ' /usr/bin/which
Using which to find which, the result will be two which, one of which is alias this is called "command alias"
Instance 4:bash built-in command cannot be found such as CD command
which CD/usr/bin/which in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/ Local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
CD is not a common command to find, this is because the CD is built in bash commands! But which by default is to find the directory within the PATH, so of course not found!
One Linux command per day (+): which