Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Specific use of the Linux which command

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

We often look for a file in linux, but we don't know where we put it. We can search it with the following commands:

Which looks at the location of the executable file. Whereis views the location of the file. Locate works with the database to view the file location. Find actually searches the hard disk to query the file name.

01. Command Overview

Find a file in an environment variable

The which command is used to find and display the absolute path of a given command, and the environment variable PATH holds the directory that needs to be traversed to find the command. The which directive looks for files that match the criteria in the directory set by the environment variable $PATH. That is, using the which command, you can see whether a system command exists and where the command is being executed.

02. Command format

Which [option] execution file name […]

03. Common option

Find the file in the environment variable-a finds everything, rather than the first file-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. -- version,-- [vV] displays version information and exits-- help displays help and exits-- skip-dot skips directories that begin with a dot in PATH-- skip-tilde skips directories that begin with waveform symbols in PATH-- show-dot does not extend dots to the current directory in the output-- show-tilde outputs waveforms for the HOME directory (not the root directory)-- tty-only if not on tty Stop the processing option on the right-- all,-a print all matches in PATH, not just the first-- read-alias,-I read the list of aliases from stdin-- skip-alias ignore option-- read-alias Do not read stdin--read-functions read shell function from stdin-- skip-functions ignore option-- read-functions; does not read stdin

04. Reference exampl

4.1 display the path of the command

[deng@localhost test] $which bash/usr/bin/bash

Description: which is based on the user's configuration of the PATH variable within the directory to search for runnable files! Therefore, different PATH configurations may find different commands.

4.2 display the alias of the command

[deng@localhost test] $which whichalias which='alias | / usr/bin/which-tty-only-read-alias-show-dot-show-tilde' / usr/bin/alias / usr/bin/which [deng@localhost test] $

4.3 ordinary users and root users have different search paths

The situation found by ordinary users

[deng@localhost test] $which pwd/usr/bin/pwd

The situation of root user search

[root@localhost ~] # which pwd/bin/pwd [root@localhost ~] #

4.4 No built-in commands found

[root@localhost ~] # which type/usr/bin/which: no type in (/ usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin) [root@localhost ~] #

This is the end of this article on the specific use of the Linux which command, more relevant Linux which content, please search the previous articles or continue to browse the following related articles hope that you will support more in the future!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report