Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Locate and find of file search

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Locate

Locate allows users to quickly search for specified files in the file system. The method is to first establish a database that includes all the file names and paths in the system, and then when looking for it, you only need to query the database without actually going deep into the file system. In the general distribution, the establishment of the database is automatically executed in crontab.

1. Command format:

Locate [Select parameters] [style]

2. Command function:

The locate command can quickly find the files when searching the database. Locate is a fuzzy search, the database is updated by the updatedb program, and the updatedb is periodically established by cron daemon. The locate command searches the database faster than the whole hard disk data, but the worse thing is that the files found by locate may not be found if they are recently created or renamed. In the default value, updatedb will run once a day. The setting value can be updated by modifying the crontab. (etc/crontab)

Locate is designated to be used to search for files that meet the criteria. It will store files and directory names in the database. When locate queries files, it will search / var/lib/mlocate/mlocage.db to find files or directories that meet the criteria of the template style. Special characters (such as "*" or "?" can be used. If the template is specified as kcpa*ner, locate will find all files or directories that start with a string of kcpa and end with ner. If the name is kcpartner, if the directory name is kcpa_ner, it will list all files in the directory, including subdirectories.

Locate instruction and find search file function is similar, but locate is through the update program to build an index database of all files and directory information in the hard disk, in the implementation of loacte directly to find the index, the query speed will be faster, the index database is generally managed by the operating system, but you can also directly issue update to force the system to modify the index database immediately.

3. Command parameters:

-e will be excluded from the scope of search. -1 if it is 1. Then start safe mode. In safe mode, users do not see files that cannot be seen by permissions. This starts to slow down because locate must go to the actual file system to obtain file permission data. -f exclude specific file systems, for example, we are not reasonable to put files in the proc file system in the database. -Q quiet mode, no error message is displayed. -n displays at most n outputs. -r use the regular expression to do the search condition. -o specify the name of the data inventory. -d specify the path to the database-h display auxiliary message-V display the version message of the program

4. Examples of use:

Example 1: search all 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/\

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 244

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report