Linux study notes -- locate command (file search command)
Locate allows users to quickly search for specified files in the system.
Features of the locate command:
1) "locate" is faster than "find" because it does not really search for files but databases. 2) for the newly created file, we can use the "locate" command to find it immediately. Generally, it cannot be found because database updates are not real-time and the database update time is maintained by the system. 3) the background database searched by the "locate" command is located in the "/var/lib/mlocate" directory. Some Linux systems may have different locations, for details, we can use "locate" to query. 4) We can use the "updatedb" command to update the database so that we can query the newly created file. 5) Not all files under the directory will be searched using the "locate" command, "/etc/updatedb. conf "this configuration file configures some rules for the" locate "command.
/Etc/updatedb. conf configuration file parsing:
1) When PRUNE_BIND_MOUNTS = "yes" is set to "yes", the search restriction is enabled. In this case, the following configuration takes effect. If it is set to "no", the search restriction is disabled. 2) PRUNEFS = a file system that is not searched after and after the search. 3) PRUNENAMES = the type of the file to be searched. 4) PRUNEPATHS = path of the file that is not searched after the search.
1. Command Format:
Locate [Option] File Name
2. Common options:
"Locate-c" queries the number of specified files. (C Indicates count) "locate-e" only displays the existing file entries. (E indicates existing) "locate-h" displays help information for the "locate" command. (H indicates help.) The case sensitivity is ignored when you search for "locate-I. (I indicates ignore) "locate-n" Maximum number of displayed items "Maximum number of displayed" Maximum number of displayed items. "Locate-r" uses regular expressions for search conditions. (R indicates regexp)
3. Common examples:
1) Find all files starting with sh in the etc directory
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: SQL;"> 2) Search for the number of all files starting with sh in the etc directory
3) Search for all files starting with sh in the etc directory and display up to 2 files
4) The new file can be queried after the database is updated.
5) The file search is case insensitive.
6) use a regular expression to search for files ending with akefile and display up to five
7) only the existing file entries are displayed.