Get the App
SLTechnology News&Howtos  ›  Servers  › 

The usage of which command in linux

Shulou Source: shulou.com Published: 2022-06-01 12:16:56 10月04日 Update

This article mainly explains "the usage of which command in linux". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the usage of the which command in linux.

1. Command format:

Which executable name

2. Command function:

The which instruction searches for the location of a system command in the path specified by the PATH variable and returns the first search result.

3. Command parameters:

-n specifies the length of the file name, which must be greater than or equal to the longest file name of all files.

The-p parameter is the same as the-n parameter, but here the path to the file is included.

-w specifies the width of the field on output.

-V displays version information

4. Use an example:

Example 1: find files and display command paths

Command:

Which lsmod

Output:

The code is as follows:

[root@localhost ~] # which pwd

/ bin/pwd

[root@localhost ~] # which adduser

/ usr/sbin/adduser

[root@localhost ~] #

Description:

Which searches for runnable files according to the directories in the PATH variables configured by the user! Therefore, the commands found in different PATH configurations are of course different!

Example 2: use which to find out which

Command:

Which which

Output:

The code is as follows:

[root@localhost ~] # which which

Alias which='alias | / usr/bin/which-tty-only-read-alias-show-dot-show-tilde'

/ usr/bin/which

[root@localhost ~] #

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!

At this point, I believe you have a deeper understanding of "the use of the which command in linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Command file content instance file name path output code parameter variable length learning search configuration different practical deeper longest same two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Information Apple Linux Huawei