Linux locate command details

Source: Internet
Author: User

Locate command

Function Description: locate allows users to quickly search for specified files in the file system. The method is to first create an index database that includes all file names and paths in the system, and then query the index database when searching, instead of going into the file system. Because Locate only searches the index database, it is much faster than find to retrieve the entire database.

In general distribution, database creation is automatically executed in crontab. Because the database used by locate is updated through crondaemon periodic creation. Generally, it is updated once a week. Therefore, files created in the last day cannot be found or deleted. You can use the update db command to manually update the database or re-adjust the update cycle.

Command Parameters

-E will be excluded from the search range.

-1 if it is 1, the security mode is enabled. In security mode, users do not see files that cannot be viewed by permissions. This slows down the speed because the locate must obtain the File Permission information from the actual file system.

-F exclude a specific file system. For example, we have no reason to store the files in the proc file system in the database.

-Q quiet mode does not display any error messages.

-N: displays up to n outputs.

-R uses the regular formula for search conditions.

-O specifies the data inventory name.

-D specifies the database path

-H: displays the secondary message

-V: displays the version information of the program.

 

Use instance

Search for related files containing a string

[Atong @ LiWenTong tmp] $ locate passwd ----- ", you can find that any file that contains passwd is displayed. We need to filter the data by ourselves.

/Etc/passwd

/Etc/passwd-

/Etc/pam. d/passwd

/Etc/security/opasswd

/Lib/security/pam_passwdqc.so

/Lib/security/pam_unix_passwd.so

 

Search for files starting with m in the/etc directory

# Locate/etc/m

/Etc/mkdir

/Etc/mask

 

Manually update the system index database

[Atong @ LiWenTong tmp] $ updatedb

Updatedb: can not open a temporary file for '/var/lib/mlocate. db'

[Atong @ LiWenTong tmp] $ sudo updatedb

[Sudo] password for atong:

[Atong @ LiWenTong tmp] $ ---> you need to wait for a while, because you still need to re-complete the retrieval of all the documents

---------------------------- Subsequent self-Summary ---------------------------

The locate function is also quite simple, that is, to search for what we want in the system, and the locate is similar to searching for database tables with the same indexes, and to find them one by one on the hard disk. this is the way, so the speed is much faster than find, but the function and search condition parameters are much worse than find. However, lightweight search is very useful.

-------------------------------------------------------------------

Search for files in Linux -- type whereis which find locate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.