Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the which command

Shulou Source: shulou.com Published: 2022-06-03 05:19:52 10月03日 Update

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.

Tags: Commands files parameters instances directories paths variables configurations different same two consumer content aliases multiple that is commonly used meaning prompt first Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology macOS OPPO Reno Linux