locate命令
locate 文件名
在后臺數(shù)據(jù)庫中按文件名搜索,搜索速度更快
?/var/lib/mlocate
#locate命令所搜索的后臺數(shù)據(jù)庫
updatedb
更新數(shù)據(jù)庫
locate搜索速度比較快缀踪;
[root@localhost ~]# ls
222 ?anaconda-ks.cfg ?牛逼
[root@localhost ~]# locate 牛
-bash: locate: 未找到命令
我們用locate命令的時(shí)候 發(fā)現(xiàn) 為找到命令锐极,我們用Yum命令遠(yuǎn)程安裝下locate
[root@localhost ~]# yum -y install mlocate
已加載插件:fastestmirror
base ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 3.6 kB ? ? 00:00 ? ??
extras ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | 3.4 kB ? ? 00:00 ? ??
updates ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| 3.4 kB ? ? 00:00 ? ??
(1/4): extras/7/x86_64/primary_db ? ? ? ?| 168 kB ? 00:00 ? ??
(2/4): base/7/x86_64/group_gz ? ? ? ? ? ?| 155 kB ? 00:02 ? ??
(3/4): base/7/x86_64/primary_db ? ? ? ? ?| 5.6 MB ? 00:04 ? ??
updates/7/x86_64/primary_db ? ?FAILED ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
http://mirrors.nju.edu.cn/centos/7.3.1611/updates/x86_64/repodata/01ced03ac066a40f0d778eda08908656cc9f5b2f6433274ed482582f9d86c88a-primary.sqlite.bz2: [Errno 12] Timeout on http://mirrors.nju.edu.cn/centos/7.3.1611/updates/x86_64/repodata/01ced03ac066a40f0d778eda08908656cc9f5b2f6433274ed482582f9d86c88a-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在嘗試其它鏡像圈膏。
(4/4): updates/7/x86_64/primary_db ? ? ? ? ? ? ? ? ? ? | 5.7 MB ? 00:01 ? ??
Determining fastest mirrors
?* base: mirrors.163.com
?* extras: mirrors.163.com
?* updates: mirrors.163.com
正在解決依賴關(guān)系
--> 正在檢查事務(wù)
---> 軟件包 mlocate.x86_64.0.0.26-6.el7 將被 安裝
--> 解決依賴關(guān)系完成
依賴關(guān)系解決
============================================================================
?Package ? ? ? ? ?架構(gòu) ? ? ? ? ? ?版本 ? ? ? ? ? ? ? ? ?源 ? ? ? ? ? ? 大小
============================================================================
正在安裝:
?mlocate ? ? ? ? ?x86_64 ? ? ? ? ?0.26-6.el7 ? ? ? ? ? ?base ? ? ? ? ?113 k
事務(wù)概要
============================================================================
安裝 ?1 軟件包
總下載量:113 k
安裝大斜否:378 k
Downloading packages:
警告:/var/cache/yum/x86_64/7/base/packages/mlocate-0.26-6.el7.x86_64.rpm: ?頭V3 RSA/SHA256 Signature, 密鑰 ID f4a80eb5: NOKEY
mlocate-0.26-6.el7.x86_64.rpm 的公鑰尚未安裝
mlocate-0.26-6.el7.x86_64.rpm ? ? ? ? ? ? ? ? ? ? ? ? ?| 113 kB ? 00:01 ? ??
從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 檢索密鑰
導(dǎo)入 GPG key 0xF4A80EB5:
?用戶ID ? ? : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
?指紋 ? ? ? : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
?軟件包 ? ? : centos-release-7-3.1611.el7.centos.x86_64 (@anaconda)
?來自 ? ? ? : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
? 正在安裝 ? ?: mlocate-0.26-6.el7.x86_64 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1/1?
? 驗(yàn)證中 ? ? ?: mlocate-0.26-6.el7.x86_64 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1/1?
已安裝:
? mlocate.x86_64 0:0.26-6.el7 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
完畢!
這樣就安裝完了暮屡。
[root@localhost ~]# locate 牛
/root/牛逼
/root/牛逼/java.pdf
這樣 我們就能測試通過驻龟;
假如我們新建一個(gè)文件温眉,然后再搜索
[root@localhost ~]# touch 牛牛
[root@localhost ~]# ls
222 ?anaconda-ks.cfg ?牛逼 ?牛牛
[root@localhost ~]# locate 牛
/root/牛逼
/root/牛逼/java.pdf
我們發(fā)現(xiàn) 搜索不了。
原因是 locate命令搜索的是?/var/lib/mlocate 下的mlocate.db數(shù)據(jù)庫
這個(gè)數(shù)據(jù)庫不是實(shí)時(shí)更新的翁狐,所以我們需要更新下數(shù)據(jù)庫类溢;
我們updatedb下,然后再搜索
[root@localhost ~]# updatedb
[root@localhost ~]# locate 牛
/root/牛牛
/root/牛逼
/root/牛逼/java.pdf
[root@localhost ~]#?
結(jié)果就出來了露懒;
locate優(yōu)點(diǎn)是 搜索速度快 闯冷,缺點(diǎn)是只能按文件名搜索;
更新數(shù)據(jù)庫配置文件/etc/updatedb.conf配置文件
我們用vi打開下
[root@localhost ~]# vi /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"
~ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
~ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
~ ? ? ? ? ? ? ? ? ? ? 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搜索限制
PRUNEFS = 搜索時(shí)懈词,不搜索的文件系統(tǒng)
PRUNENAMES = 搜索時(shí)蛇耀,不搜索的文件類型
PRUNEPATHS = 搜索時(shí),不搜索的路徑
比如這里的tmp路徑的文件 默認(rèn)配置是搜索不到的坎弯;