We often want to find a file in Linux, but we don't know where it is. We can use the following commands to search:
01. Command Overview Find files in environment variables The which command is used to find and display the absolute path of a given command. The environment variable PATH stores the directories that need to be traversed when searching for commands. The which command searches for matching files in the directories set by the environment variable $PATH. In other words, by using the which command, you can see whether a system command exists and where the command is executed. 02. Command format 03. Common options Search for files in environment variables -a Search all contents instead of the first file -n <file name length> Specify the file name length. The specified length must be greater than or equal to the longest file name among all files. -p <filename length> is the same as the -n parameter, but the <filename length> here includes the file path. -w specifies the width of the output columns. -V Display version information. --version, -[vV] show version information and exit --help show this help message and exit --skip-dot skip directories in PATH that begin with a dot --skip-tilde skip directories in PATH that begin with a tilde --show-dot do not expand dot to current directory in output --show-tilde print tilde for HOME directory (non-root) --tty-only if not on a tty, stop processing options to the right --all, -a print all matches in PATH, not just the first --read-alias, -i read alias list from stdin --skip-alias ignore option --read-alias; do not read stdin --read-functions Read shell functions from stdin --skip-functions Ignore option --read-functions; do not read stdin 04. Reference examples 4.1 Display command path [deng@localhost test]$ which bash /usr/bin/bash Description: which searches for executable files based on the directories in the PATH variable configured by the user! Therefore, different PATH configuration contents may find different commands. 4.2 Display command aliases [deng@localhost test]$ which which alias 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 Common user search scenarios [deng@localhost test]$ which pwd /usr/bin/pwd Root user search scenario [root@localhost ~]# which pwd /bin/pwd [root@localhost ~]# 4.4 Cannot find built-in commands [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 about the specific usage of the Linux which command. For more relevant Linux which content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Echarts tutorial on how to implement tree charts
>>: Detailed explanation of common commands in MySQL 8.0+
Table of contents Tutorial Series 1. User Managem...
Docker underlying technology: The two core techno...
A jQuery plugin every day - to make search histor...
Table of contents Problems encountered during dev...
introduction I discovered a problem before: somet...
background Now the company's projects are dev...
Recently, a service has an alarm, which has made ...
1. Create a new virtual machine in VMware 15.5 1....
Table of contents 1. Conditional access attribute...
Since I usually use the docker build command to g...
This article explains how to install MySQL from a...
System version [root@ ~]# cat /etc/redhat-release...
The effect is as follows:Reference Program: <!...
Table of contents 1. Introduction 2. Code Impleme...
Written in front A database is essentially a shar...