Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the which command on Linux system

Shulou Source: shulou.com Published: 2022-06-01 21:23:54 10月04日 Update

This article mainly introduces the Linux system which command how to use, the article is very detailed, has a certain reference value, interested friends must read it!

The main function of the Linux system 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.

Syntax which [file...] Parameter:-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.

Case demonstration: example 1: find files and display command paths

Command:

Which lsmod

Output:

[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:

[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!

Example 3: find out the command cd

Command:

Which cd

Output:

Description:

The common command of cd can't be found! Why? This is because cd is a built-in command from bash! But which defaults to find the directory specified in PATH, so of course you can't find it!

The above is all the contents of this article entitled "how to use which commands in Linux system". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Command file system output content instance path parameter variable file name directory article length search configuration different longest same two value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi Shulou Information Docker Shulou Tech Info