Introduction and usage of locate

Source: Internet
Author: User

Introduction

The locate command is used to find files. Locate can quickly search for specified files in the file system. The method is to first create a database that includes the names and paths of all files in the system. Then, you only need to query the database when searching, instead of going into the file system.Therefore, it requires a database (default: slocate. DB), a configuration file (updatedb. conf), and a crontab (scheduled execution) 

  • Run updatedb first, which can be executed directly or in crontab.
  • Search for the generated/var/lib/slocate. DB database.

So

  • Locate is faster than find because it does not really search for files, but queries databases.
  • The locate search is not real-time, but is based on database updates. It is generally maintained by the system itself.
  • Locate Database Upgrade command: locate -- u # note that there is a space

# Ls-lart mlocate. DB # Before update
-RW-r ----- 1 root slocate 1286901 Aug 8 mlocate. DB
# Updatedb
# Ls-lart mlocate. DB # After update
-RW-r ----- 1 root slocate 1296268 Aug 8 mlocate. DB


Usage
# Locate-S // --> View statistics, directories, files, and bits.
Database /var/lib/mlocate/mlocate.db:    3,315 directories    37,228 files    1,504,439 bytes in file names    594,851 bytes used to store database
# Locate-V // --> View version information
<pre name="code" class="plain">mlocate 0.22.2Copyright (C) 2007 Red Hat, Inc. All rights reserved.This software is distributed under the GPL v.2.This program is provided with NO WARRANTY, to the extent permitted by law.
 

# Locate-H // --> View help information

Usage: locate [OPTION]... [PATTERN]...Search for entries in a mlocate database.  -b, --basename         match only the base name of path names  -c, --count            only print number of found entries  -d, --database DBPATH  use DBPATH instead of default database (which is                         /var/lib/mlocate/mlocate.db)  -e, --existing         only print entries for currently existing files  -L, --follow           follow trailing symbolic links when checking file                         existence (default)  -h, --help             print this help  -i, --ignore-case      ignore case distinctions when matching patterns  -l, --limit, -n LIMIT  limit output (or counting) to LIMIT entries  -m, --mmap             ignored, for backward compatibility  -P, --nofollow, -H     don't follow trailing symbolic links when checking file                         existence  -0, --null             separate entries with NUL on output  -S, --statistics       don't search for entries, print statistics about each                         used database  -q, --quiet            report no error messages about reading databases  -r, --regexp REGEXP    search for basic regexp REGEXP instead of patterns      --regex            patterns are extended regexps  -s, --stdio            ignored, for backward compatibility  -V, --version          print version information  -w, --wholename        match whole path name (default)
# Locate/etc/SH // --> Find/etc/sh *
/etc/shadow/etc/shadow-/etc/shadow.bup/etc/shadow.bup.20140725-214324/etc/shells
# Locate-N 5 Apache // --> only find the directory containing Apache, 5 of which are displayed
/etc/selinux/targeted/modules/active/modules/apache.pp/opt/cpf/oma/3rdparty/apache-tomcat/opt/cpf/oma/3rdparty/apache-tomcat/LICENSE/opt/cpf/oma/3rdparty/apache-tomcat/NOTICE/opt/cpf/oma/3rdparty/apache-tomcat/RELEASE-NOTES
# Locate-r makefile $ // --> Find the directory of the file ending with makefile
/usr/share/doc/bcel-5.2/verifier/GNUmakefile
# Locate-N 3-R ^ \/OPT // --> Find the directory starting with/OPT and display only three rows
/opt/opt/cpf/opt/oss
# Locate-I/http // --> Find/HTTP directory, case-insensitive
/usr/share/perl5/Net/HTTP/NB.pm/usr/share/perl5/URI/http.pm/usr/share/perl5/URI/https.pm

# Locate-C httpd. conf// --> Count the number found 

3

# Cat/etc/updatedb. conf // --> Configuration File

PRUNE_BIND_MOUNTS = "yes"PRUNEFS="9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fusectl gfs gfs2 hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs efs100 lofs"PRUNENAMES = ".git .hg .svn"PRUNEPATHS = "/afs /media /net /sfs /tmp /udev /var/cache/ccache/var/spool/cups /var/spool/squid /var/tmp"PRUNEPATHS="/efs /efsroots"export PRUNEPATHS


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.