3.locate
Locate allows users to quickly search the file system for specific files. The method is to set up a database that includes all the file names and paths within the system, and then simply query the database when looking for it, rather than actually going deep into the file system. In the general distribution, the establishment of the database is placed in the crontab automatic execution.
3.1. Command format:
Locate [Select parameters] [style]
3.2. Command function:
The locate command can quickly find the file when searching the database, the database is updated by the UpdateDB program, UpdateDB is created periodically by Cron Daemon, and the locate command searches the database faster than the entire data from the hard disk. But the worse is locate found the file if recently established or newly renamed, may not be found, in the default value, UpdateDB will run once a day, can be modified crontab to update the set value. (Etc/crontab)
Locate designated to search for eligible files, it will be stored in the file and directory name of the database, to find matching template style conditions of the file or directory, you can use special characters (such as "*" or "?" And so on) to specify the template style, as specified by Kcpa*ner, locate will find all files or directories that have a starting string of KCPA and end with NER, such as the name Kcpartner if the directory name is Kcpa_ner, all files including subdirectories are listed under that directory.
Locate command and find find files similar function, but locate is through the update program to the hard disk all the files and directory data first set up an index database, in the execution of LOACTE directly to find the index, query faster, the index database is generally managed by the operating system, However, you can also directly release the update to force the system to immediately modify the index database.
3.3. Command parameters:
-E will be excluded from the scope of the search.
-1 if it is 1. The security mode is started. In safe mode, the user does not see files that the permissions cannot see. This slows down because the locate must get access to the file in the actual file system.
-F excludes specific file systems, for example, we have no reason to put the files in the proc file system in the database.
-Q Quiet mode, no error message is displayed.
-N displays at most x outputs.
-R uses the normal arithmetic to do the searching condition.
-o Specifies the name of the data inventory.
-d Specifies the path of the repository
-H Display Auxiliary message
-V Displays the version message of the program
3.4. Usage examples:
Example 1: Find all files related to JPS
[Email protected] ~]$ Locate jps/data/spark/jdk1.7.0_60/bin/jps/data/spark/jdk1.7.0_60/man/ja/man1/jps.1/data/ Spark/jdk1.7.0_60/man/ja_jp. utf-8/man1/jps.1/data/spark/jdk1.7.0_60/man/man1/jps.1/log/software/jdk1.7.0_60/bin/jps/log/software/jdk1.7.0_ 60/man/ja_jp. Utf-8/man1/jps.1/log/software/jdk1.7.0_60/man/man1/jps.1/usr/java/jdk/bin/jps/usr/java/jdk/man/ja/man1/jps.1/ Usr/java/jdk/man/ja_jp. Utf-8/man1/jps.1/usr/java/jdk/man/man1/jps.1
Example 2: Search all files in the ETC directory that begin with SH
[Email protected] ~]$ Locate/etc/sh/etc/shadow/etc/shadow-/etc/shadow.bak/etc/shells
A detailed look at the search command under Linux (locate)