How to use the which command
NAME
The which-show the full path of (shell) commands displays the full path to the command.
SYNOPSIS
Which [options] [-] programname [...]
DESCRIPTION
Which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same algorithm as bash (1).
Which can take one or more parameters. For each parameter, when this parameter is typed into the shell command prompt, it prints the full path to the executable file to standard output. Using the same algorithm as bash (that is, showing which one was found first), it executes the search executable or script file in the directory listed in the PATH environment variable.
Example 1: find files and display command paths
Description:
Which searches for runnable blocks according to the directories in the PATH variables configured by the user! So, of course, different PATH configurations find different commands.
Example 2: use which to find which
Description:
Unexpectedly, there will be two which, one of which is alias, which is the so-called "command alias", which means that typing which will be equal to the following string of commands!
Example 3: find out the command cd
Description:
The commonly used command cd can't be found? Why? This is because cd is a bash built-in command! But which defaults to looking for directories contained in PATH, so of course you can't find them.