Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the which command of linux to find files

Shulou Source: shulou.com Published: 2022-06-02 20:09:30 09月18日 Update

This article will explain in detail about the use of linux's which command to find files. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

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.

Operation and maintenance staff often use which commands in their daily work to check the existence of a system command, or to find out the specific location of the command.

Syntax format: which [parameters] [file]

Common parameters:

-n specifies the file name length, which must be greater than or equal to the longest file name of all files-p is the same as the-n parameter, but here includes the file path-w specifies the width of the field when output-V displays version information

Reference example

Find the file and display the command path:

[root@linuxcool ~] # which bash

/ bin/bash

[root@linuxcool ~] # which adduser

/ usr/sbin/adduser

Description: which is based on the user configuration of the PATH variable within the directory to search for runnable files! Therefore, the commands found in different PATH configurations are of course different!

Use which to find which:

[root@linuxcool ~] # which which

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

Explanation: there will be two which, one of which is alias, which is the so-called [command alias], meaning that entering which will be equal to the following string of commands! The real Bash built-in command cannot be found, such as the cd command:

[root@linuxcool ~] # which cd

Explanation: cd this commonly used command can not be found ah! 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!

View the default jdk:

[root@linuxcool ~] # which java

/ usr/bin/java

The directory looked up by which, the value of the PATH variable:

[root@linuxcool ~] # echo $PATH

/ usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin on the use of linux which command to find files to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Commands files parameters variables directories paths locations contents commonly used file names more articles systems length reference search configuration different good practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Tech Info Docker Huawei Xiaomi