Search and compress filing of files
Search and compress filing of files
Locate
Find
Compression and archiving
Locate
Main use
Query the pre-built file index database on the system
Locate-find files by namelocate [OPTION]... PATTERN...
When locate queries files, it searches / var/lib/mlocate/mlocage.db. The database is automatically updated periodically when the system is idle. The manual update command is updatedb. The construction of the index needs to traverse the entire root file system, which consumes more resources. However, locate has the following features:
1. Fuzzy search, fast 2. 5%. Non-real-time search, the search is the full path of the file, not the file name 3. It is possible to search only directories where the user has read and execute permissions
Common parameters
-d:-- database, specify the directory where the database is located
-I:-- ignore-case, ignore case when searching
-n N: enumerate only the first N matching items
-r:-- regexp, regular expressions are supported when searching
Use the example
Look for files that start with sh in the / etc/ directory:
[root@centos7 #] locate / etc/sh / etc/shadow/etc/shadow-/etc/shells [root@centos7 ~ #] locate-r "/ etc/\