Linux how to use the locate command to find data

  

The locate command is one of the Linux lookup commands. It can be used to find data. It is similar to the find command, but the find command is more resource-consuming. The following small series will give you a detailed description of locate. The usage of the command.

locate allow users to specify the file if there is a very fast file search system. The method is to first create a database that includes all the file names and paths in the system, and then only need to query the database when searching, without actually going deep into the file system. In the general distribution, the creation of the database is automatically performed in the crontab.

1. Command format:

Locate [Select Parameters] [Style]

2. Command function:

The locate command can quickly find the file when searching the database. The database is updated by the updatedb program. The updatedb is periodically created by the cron daemon. The locate command is more than the entire hard disk data when searching for the database. Searching for data is fast, but the worse one is that if the file found by locate is recently established or just renamed, it may not be found. In the default value, updatedb will run once a day, and the set value can be updated by modifying crontab. . (etc/crontab)

locate is used to search for qualified files. It will store the file and directory name in the database to find files or directories that match the style of the template. Special characters can be used. For example, ”*” or ”?” etc. to specify the template style, if the specified template is kcpa*ner, locate will find all files or directories whose starting string is kcpa and ending with ner, such as the name If kcpartner is named kcpa_ner, it will list all files including subdirectories in that directory.

The locate command and find find the file function is similar, but locate is to use the update program to create an index database for all files and directory data in the hard disk, directly find the index when executing loacte, the query speed will Faster, the index database is generally managed by the operating system, but it can also be directly updated to force the system to modify the index database immediately.

3. Command parameters:

-e will be excluded from the scope of the search.

-1 if yes 1. Then start safe mode. In safe mode, users will not see files that they cannot see. This will start to slow down because locate must go to the actual file system to get the file's permission data.

-f Exclude 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 will be displayed.

-n Display up to n outputs.

-r Use the regular expression to do the search.

-o Specifies the name of the data library.

-d Specify the path of the database

-h Display the auxiliary message

-V Display the version information of the program
Previous12Next page Total 2 pages

Copyright © Windows knowledge All Rights Reserved