1024programmer Linux What is the locate command – linux operation and maintenance

What is the locate command – linux operation and maintenance

The locate command is used to find files or directories. The locate command is much faster than [find -name] because it does not search for a specific directory, but a database. The syntax is [locate [OPTION] … [PATTERN]…].

locate command:

1. Command introduction

The locate(locate) command is used to find a file or directory. The locate command is much faster than find -name because it does not search a specific directory, but a database /var/lib/mlocate/mlocate.db. This database contains all local file information. The Linux system automatically creates this database and automatically updates it once a day. Therefore, when we use whereis and locate to find files, we sometimes find deleted data, or just created files, but cannot find them. The reason is because the database file does not have Updated. To avoid this situation, you can use the updatedb command to manually update the database before using locate. The whole locate work is actually composed of four parts:

  • /usr/bin/updatedb is mainly used to update the database, through crontab Automatically completed

  • /usr/bin/locate query file location

  • /etc/updatedb.conf updatedb configuration file

  • /var/lib/mlocate/mlocate.db file for storing file information

2. Usage

locate [OPTION]... [PATTERN]...

3. Options

strong>

 -b, --basename match only the base name of path names
   -c, --count output only count found
   -d, --database DBPATH use the database specified by DBPATH instead of the default database /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 show help
   -i, --ignore-case ignore case
   -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 Quiet mode, no error messages will be displayed
   -r, --regexp REGEXP use basic regular expressions
       --regex use extended regular expressions
   -s, --stdio ignored, for backward compatibility
   -V, --version display version information
   -w, --wholename match whole path name (default)

4. Example

Example 1: Search for all files starting with my in the etc directory

[root@cent6 lib]# locate /etc/my
 /etc/my.cnf

Example 2: Newly added files cannot be located, use updatedb

[root@cent6 ~]#  touch new.txt
 [root@cent6 ~]# locate new.txt
 [root@cent6~]#updatedb
 [root@cent6 ~]# locate new.txt
 /root/new.txt

Example 3: updatedb configuration file /etc/updatedb.conf

[root@cent6 ~]  # cat /etc/updatedb.conf
 PRUNE_BIND_MOUNTS = "yes"
 PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fusetl gfs gfs2 hugetlbfs inotifyfs iso9660 jffs2 luster mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs"
 PRUNENAMES = ".git.hg.svn"
 PRUNEPATHS = "/afs /media /net /sfs /tmp /udev /var/cache/ccache /var/spool/cups /var/spool/squid /var/tmp"

Related learning Recommendation: linux video tutorial

The above is the detailed content of the locate command. For more information, please pay attention to other related articles on 1024programmer.com!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/what-is-the-locate-command-linux-operation-and-maintenance/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

The latest and most comprehensive programming knowledge, all in 1024programmer.com

© 2023 1024programmer - Encyclopedia of Programming Field
Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

首页
微信
电话
搜索