In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
The editor today takes you to understand how to use the locate command in the Linux system. The knowledge points in the article are introduced in great detail. Friends who feel helpful can browse the content of the article together with the editor, hoping to help more friends who want to solve this problem to find the answer to the problem. Let's follow the editor to learn more about "what is the use of locate commands in the Linux system".
1.1 brief introduction
The locate command is used to find a file or directory. The locate command is much faster than find-name because instead of searching for specific directories, it searches for a database / var/lib/mlocate/mlocate.db. This database contains all the local file information. The Linux system automatically creates this database and automatically updates it once a day. Therefore, when we look for files with whereis and locate, we sometimes find data that has been deleted, or files that have just been created, but cannot be found because the database files have not been updated. To avoid this, you can manually update the database using the updatedb command before using locate. The whole locate work is actually made up of four parts:
/ usr/bin/updatedb: mainly used to update the database, done automatically through crontab
/ usr/bin/locate: query file location
/ etc/updatedb.conf: configuration file for updatedb
/ var/lib/mlocate/mlocate.db: the file where the file information is stored
Locate reads one or more databases prepared by updatedb and writes files that meet the matching PATTERN to standard output, one file name per line. If the-- regex option is not specified, PATTERN can contain wildcards. If the PATTERN does not contain any wildcards, the locate command looks in * PATTERN* mode.
By default, the locate command does not check whether the files in the database still exist or report the files generated after the last update to the database.
1.2Use locate [OPTION]... [PATTERN]... 1.3 option-A,-- all prints all files that match PATTERNs-b,-- basename only files whose names match PATTERNs (for example, / test/test.txt, then basename is test.txt)-c,-- count only prints the number of files matched, not the file name itself-d,-- database DBPATH uses DBPATH instead of the default database. DBPATH is a list of database names separated by: (colon)-e,-- existing prints only the file-L that exists when locate is called,-- follow when used with the-e option, if the file is a soft link file, it will get the actual file corresponding to the soft link (this is the default text of the locate command). -h,-- help print help document information-- I,-- ignore-case ignore case-l,-- limit,-n LIMIT when performing file pattern matching, exit-P,-- nofollow,-H when successfully matching the number of LIMIT files, if the file is a soft-linked file when used with the-e option At this time, it does not follow the linked actual file-0,-- null outputs with ASCII NUL as the delimiter-S,-- statistics gets the statistics of each search database-Q,-- quiet when it encounters errors and does not print relevant information-r,-- regexp REGEXP looks for a basic pattern matching REGEXP. In this case, PATTERNs-V,-- version prints locate version information and license information-w,-- wholename matches the full pathname (default). For example, to find a file with the file name NAME (not * NAME*), you can use the following:
# locate-b'\ NAME' should be\ itself a wildcard character, so implicit conversion to * NAME*. is prohibited here
1.4 use example 1) search for all files under the directory that begin with sh
# locate / etc/sh / etc/shadow / etc/shadow- / etc/shells2) contains files related to a string
# locate passwd / etc/passwd / etc/passwd- / etc/pam.d/passwd / etc/security/opasswd / usr/bin/gpasswd / usr/bin/grub2-mkpasswd-pbkdf2 / usr/bin/kpasswd / usr/bin/lppasswd / usr/bin/passwd / usr/bin/smbpasswd. 3) limit the number of displays
If you display too much content, you can use the-n option to limit the number of displays.
# locate-n 5 passwd / etc/passwd / etc/passwd- / etc/pam.d/passwd / etc/security/opasswd / usr/bin/gpasswd4) use regular expressions
When you need to find information that meets a specific rule, you can use the-r option to match the corresponding regular expression
/ / find the file that starts with / var/lib/rpm # locate-r ^ / var/lib/rpm/ var/lib/rpm/ var/lib/rpm-state / var/lib/rpm/.dbenv.lock / var/lib/rpm/.rpm.lock.... / / find the file ending with zip # locate-r zip$ / usr/bin/funzip / usr/bin/gpg-zip / usr/bin/gunzip / usr/bin/gzip / usr/bin/mzip / usr/bin/unzip / usr/bin/zip / usr/lib64/libreoffice/share/config/images.zip / usr/lib64/libreoffice/share/config/images_crystal.zip. 5) determine whether a file in a directory exists (soft link)
# ls.. / lib | while read line; do if [- f.. / lib/$line]; then temp= "$(locate" $line ")"; if [- n "$temp"]; then echo $line Fi fi done1.5 updatedb configuration file / 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 fuse.sshfs fusectl gfs gfs2 gpfs 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" PRUNENAMES = ".git .hg .svn" PRUNEPATHS = "/ afs / media / mnt / net / sfs / tmp / udev / var/cache/ccache / var/ Lib/yum/yumdb / var/spool/cups / var/spool/squid / var/tmp "PRUNE_BIND_MOUNTS: indicates whether to conduct a restricted search
PRUNEFS: indicates the type of file system that is excluded from retrieval
PRUNENAME: indicates the file types that are excluded from retrieval
PRUNEPATHS: indicates the directory of files that are excluded from retrieval
Thank you for your reading, the above is the whole content of "what is the use of locate commands in Linux system?" learn friends to hurry up to operate it. I believe that the editor will certainly bring you better quality articles. Thank you for your support to the website!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.