溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

locate指令有什么用

發(fā)布時間:2020-11-03 10:14:41 來源:億速云 閱讀:161 作者:小新 欄目:建站服務(wù)器

這篇文章主要介紹locate指令有什么用,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

locate指令是用來查找文件或目錄, locate命令要比【find -name】快得多,原因在于它不搜索具體目錄,而是搜索一個數(shù)據(jù)庫,語法是【locate [OPTION]... [PATTERN]...】。

locate指令:

1、命令簡介

locate(locate) 命令用來查找文件或目錄。 locate命令要比find -name快得多,原因在于它不搜索具體目錄,而是搜索一個數(shù)據(jù)庫/var/lib/mlocate/mlocate.db 。這個數(shù)據(jù)庫中含有本地所有文件信息。Linux系統(tǒng)自動創(chuàng)建這個數(shù)據(jù)庫,并且每天自動更新一次,因此,我們在用whereis和locate 查找文件時,有時會找到已經(jīng)被刪除的數(shù)據(jù),或者剛剛建立文件,卻無法查找到,原因就是因為數(shù)據(jù)庫文件沒有被更新。為了避免這種情況,可以在使用locate之前,先使用updatedb命令,手動更新數(shù)據(jù)庫。整個locate工作其實是由四部分組成的:

  • /usr/bin/updatedb   主要用來更新數(shù)據(jù)庫,通過crontab自動完成的

  • /usr/bin/locate         查詢文件位置

  • /etc/updatedb.conf   updatedb的配置文件

  • /var/lib/mlocate/mlocate.db  存放文件信息的文件

2、用法

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

3、選項

  -b, --basename         match only the base name of path names
  -c, --count            只輸出找到的數(shù)量
  -d, --database DBPATH  使用DBPATH指定的數(shù)據(jù)庫,而不是默認數(shù)據(jù)庫 /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             顯示幫助
  -i, --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 eachused database
  -q, --quiet            安靜模式,不會顯示任何錯誤訊息
  -r, --regexp REGEXP    使用基本正則表達式
      --regex            使用擴展正則表達式
  -s, --stdio            ignored, for backward compatibility
  -V, --version          顯示版本信息
  -w, --wholename        match whole path name (default)

4、示例

示例1: 搜索etc目錄下所有以my開頭的文件

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

示例2:新增的文件無法locate,使用updatedb

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

示例3:updatedb的配置文件/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 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"
PRUNENAMES = ".git .hg .svn"
PRUNEPATHS = "/afs /media /net /sfs /tmp /udev /var/cache/ccache /var/spool/cups /var/spool/squid /var/tmp"

以上是locate指令有什么用的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI