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 establishment of the database is placed in the crontab automatic execution.
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, 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:
-N display of at most nth outputs
-d Specifies the path of the repository
-V Displays the version message of the program
4. Use instances: find All files related to pwd
Command:
locate pwd
Output:
[begin] 2016/1/1 14:49:58[[email protected] ~]# locate pwdlocate: can not stat () '/var/lib/mlocate/mlocate.db ': no such file or directory[[ email protected] ~]# updatedb[[email protected] ~]# locate pwd/bin/pwd/etc/ . pwd.lock/lib/modules/2.6.32-431.el6.i686/kernel/drivers/watchdog/hpwdt.ko/lib/modules/2.6.32-573.12.1. El6.i686/kernel/drivers/watchdog/hpwdt.ko/sbin/unix_chkpwd/usr/bin/pwdx/usr/include/pwd.h/usr/lib/cracklib_ dict.pwd/usr/lib/python2.6/lib-dynload/spwdmodule.so/usr/share/cracklib/cracklib-small.pwd/usr/share/cracklib/ Pw_dict.pwd/usr/share/man/man0p/pwd.h.0p.gz/usr/share/man/man1/pwd.1.gz/usr/share/man/man1/pwdx.1.gz/usr/share /man/man1p/pwd.1p.gz/usr/share/man/man3/lckpwdf.3.gz/usr/share/man/man3/ulckpwdf.3.gz/usr/share/man/man8/unix_ chkpwd.8.gz/usr/share/perl5/pwd.pl/usr/src/kernels/2.6.32-431.el6.i686/include/config/hpwdt/usr/src/kernels/ 2.6.32-431.el6.i686/include/config/hpwdt/nmi/usr/src/kernels/2.6.32-431.el6.i686/include/config/hpwdt/nmi/decoding.h[end] 2016/ 1/1 14:57:56
Note: When using locate for the first time, you need to use UpdateDB, and then directly query all files related to PWD
Example 2: Search all files in the ETC directory that begin with SH
Command:
locate/etc/sh
Output:
[BEGIN] 2016/1/1 15:01:55[[email protected] ~]# Locate/etc/sh/etc/shadow/etc/shadow-/etc/shells[end] 2016/1/1 15:02:03
Example 3: Search the ETC directory for all files starting with M
Command:
locate/etc/m
output:
[begin] 2016/1/1 15:35:18[[email protected] ~]# locate /etc/m/etc/magic/etc/ mail.rc/etc/mailcap/etc/makedev.d/etc/man.config/etc/mime.types/etc/mke2fs.conf/etc/modprobe.d/etc/motd/etc/ mtab/etc/mtools.conf/etc/my.cnf/etc/makedev.d/00macros/etc/makedev.d/01alsa/etc/makedev.d/01cdrom/etc/ makedev.d/01console/etc/makedev.d/01ftape/etc/makedev.d/01generic/etc/makedev.d/01ia64/etc/makedev.d/01ibcs/ etc/makedev.d/01ide/etc/makedev.d/01ipfilter/etc/makedev.d/01isdn/etc/makedev.d/01linux-2.6.x/etc/makedev.d/ 01linux1394/etc/makedev.d/01mouse/etc/makedev.d/01qic/etc/makedev.d/01raid/etc/makedev.d/01redhat/etc/ makedev.d/01s390/etc/makedev.d/01sound/etc/makedev.d/01std/etc/makedev.d/01undocumented/etc/makedev.d/01v4l/ etc/makedev.d/02cciss/etc/makedev.d/02dac960/etc/makedev.d/02ida/etc/makedev.d/02linux-2.6.x/etc/modprobe.d/ anaconda.conf/etc/modprobe.d/blacklist.conf/etc/modprobe.d/dist-alsa.conf/etc/modprobe.d/dist-oss.conf/etc/ Modprobe.d/dist.conf/etc/modprobe.d/openfwwF.conf/etc/modprobe.d/vmware-tools.conf/root/redis-3.0.6/deps/lua/etc/min.c[end] 2016/1/1 15:35:25
A Linux locate command every day