commands for locating and locating files
Command |
Function |
Command |
Function |
which |
Find the location of the file from path |
Find |
Find all documents that meet your requirements |
Whereis |
Find the path to a specific program |
Locate |
Find the file location from the index |
9.1 Which
Grammar
which command
Description
The location of the command is found sequentially from the directory listed in the PATH environment variable, and the name of the full path is displayed. When the first qualifying program file is found, the search stops immediately, omitting the remaining directories that are not searched.
example, find the location of the program file for the LS command:
which LS
System output:
/usr/bin/ls
9.2 Whereis
Grammar
Whereis [option] Name
Description
Find out the executable files, source code files, and manpage paths for the specific program. The name you provide will be first removed from the predecessor path and any. ext extension.
whereis will only be searched in the standard Linux directory.
Common options
-B
Only the executable file is searched.
-M
Search Manpage only.
-S
Only source code files are searched.
-B Directory
Changes or limits the directory to search for executable files.
-M directory
Changes or limits the search Manpage directory.
-S Directory
Change or qualify the directory where the source code files are searched.
9.3 Find
Grammar
Find paths expression [action]
Description
Use paths as the search starting point to find each file that matches the expression criteria and perform the action represented by action on the file. Expression is a search condition consisting of an option that represents the matching item and a parameter that represents the matching pattern.
An action is a processing action that has an option to represent "processing" and an action parameter composition. If you do not specify an action, the default action is to display the file name.
Common search criteria
-name pattern
-path pattern
-lname pattern
Locate the file with the name, path name, or symbolic link target matching the pattern pattern. Pattern can contain the shell's file name wildcard character, which is relative to the search starting point.
Common handling actions
-print
Displays the relative path of the file relative to the start of the search.
-exec cmd/;
Executes the specified shell command. If CMD contains any shell special characters, they must precede them with a/sign, lest the shell execute them immediately. In cmd, you can use the "{}" symbol (including double quotation marks) to represent the file found by find.
9.4 Locate
Grammar
Locate patterns
Description
The first time the locate is executed, it creates an index database that, when executed again, quickly finds the location of the file from the index database. Locate is a great place to search repeatedly for infrequently changed directories, but for old files that have just been renamed and for newly created files, locate cannot be found unless the database is rebuilt.
UpdateDB
Grammar
updatedb [option]
Description
Update the index database for slocate.
Options
-E Directories
Skip the directories listed in directories.
CentOS location, find file commands