Common Linux commands (15th) and common linux commands
We often search for a file in linux, but do not know where it is stored. You can use the following commands to search:
Which: view the location of the executable file.
Whereis view the file location.
Use locate with the database to view the file location.
Find actual search hard disk Query file name.
1.Command Format:
Which Executable File Name
2.Command function:
The role of the which command: In the PATH specified by the PATH variable, search for the location of a system command and return the first search result. That is to say, by using the which command, you can see whether a system command exists and where the command is executed.
3.Command parameters:
-N indicates the length of the file name. The specified length must be greater than or equal to the longest file name in all files.
The-p and-n parameters are the same, but the file path is included here.
-W specifies the width of the field when the output is made.
-V: display version information
4. Command example:
Instance 1:Find the file and display the command path
Command: where pwd
[root@localhost ~]# which pwd/bin/pwd[root@localhost ~]# which rm/bin/rm
Which searches for executable files based on the directory in the PATH variable configured by the user! Therefore, the command paths found for different PATH configurations are certainly different!
Example 2:Use which to find which
Command: which
[root@localhost ~]# which whichalias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' /usr/bin/which[root@localhost ~]#
There are actually two which, one of which is alias. This is the so-called "command alias", which means that the input of which will wait for the subsequent commands!
Example 3:Find the cd command
Command: which cd
[root@localhost ~]$ which cd/usr/bin/which: no cd in (/usr/local/ant/bin:/usr/local/jdk/bin:/home/oracle/software/product/client/10.2/bin:/usr/local/jdk/bin:/usr/local/ant/bin:/usr/local/ant/bin:/usr/local/jdk/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:.:/home/psc/bin:/home/psc/bin)[root@localhost ~]$
Because cd is a built-in bash command! However, by default, which finds the standard directory in the PATH, so of course it cannot be found!