Linux common Commands (17)-Locate

Source: Internet
Author: User

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 database is set up in CRontab automatic execution.


1. command format:

Locate [select parameter] [style]


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. Command parameters:

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

< Span style= "font-family:comic Sans MS" >-1   &NBSP; If   is  1. The security mode is started. In safe mode, the user does not see the Span style= "FONT-SIZE:14PX; text-indent:21pt; margin:0px; padding:0px "> file. This will slow down because  locate  has to get the file's permission data.

< Span style= "font-family:comic Sans MS" >-f &NBSP, &NBSP;&NBSP; Exclude specific file systems, for example, we have no reason to put the files in the  proc  file system Put it in the database.

- Q Quiet mode, no error messages are 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


4. Command instance:

instance One :  Find and pwd all related files

command: locate pwd

Peida-virtualbox ~ # Locate pwd/bin/pwd/etc/.pwd.lock/sbin/unix_chkpwd/usr/bin/pwdx/usr/include/pwd.h/usr/lib/ python2.7/dist-packages/twisted/python/fakepwd.py/usr/lib/python2.7/dist-packages/twisted/python/fakepwd.pyc/ usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.py/usr/lib/python2.7/dist-packages/twisted/ Python/test/test_fakepwd.pyc/usr/lib/syslinux/pwd.c32/usr/share/help/c/empathy/irc-join-pwd.page/usr/share/ help/ca/empathy/irc-join-pwd.page/usr/share/help/cs/empathy/irc-join-pwd.page/usr/share/help/de/empathy/ Irc-join-pwd.page/usr/share/help/el/empathy/irc-join-pwd.page

Example two: search All files in the ETC directory that begin with SH

command: locate/etc/sh

Peida-virtualbox ~ # Locate/etc/sh/etc/shadow/etc/shadow-/etc/shells




Linux common commands (17)-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.