We often search for a file in linux, but do not know where it is stored. you can use the following commands to search
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.
The which command searches for the location of a system command in the PATH specified by the PATH variable and returns 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.
1. command format:
Which executable file name
2. command functions:
The which command searches for the location of a system command in the PATH specified by the PATH variable and returns the first search result.
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. example:
Instance 1: search for files and display command paths
Command:
Which lsmod
Output:
Copy codeThe code is as follows:
[Root @ localhost ~] # Which pwd
/Bin/pwd
[Root @ localhost ~] # Which adduser
/Usr/sbin/adduser
[Root @ localhost ~] #
Note:
Which searches for executable files based on the directory in the PATH variable configured by the user! Therefore, the commands found for different PATH configurations are certainly different!
Instance 2: Use which to locate which
Command:
Which
Output:
Copy codeThe code is as follows:
[Root @ localhost ~] # Which
Alias which = 'Alias |/usr/bin/which -- tty-only -- read-alias -- show-dot -- show-tilde'
/Usr/bin/which
[Root @ localhost ~] #
Note:
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!
Instance 3: Find the cd command
Command:
Which cd
Output:
Note:
The common cd command cannot be found! Why? This is because cd is a built-in bash command! However, by default, which finds the standard directory in the PATH, so it must not be found!