locate命令
locate 文件名
在后台数据库中按文件名搜索,搜索速度更快
/var/lib/mlocate
locate命令所搜索的后台数据库
updatedb更新数据库
locate搜索速度比较快;
我们用locate命令的时候 发现 未找到命令,我们用Yum命令远程安装下locate
[root@localhost ~]# yum -y install mlocate
安装完成后
[root@localhost ~]# locate we
locate: 无法执行 stat () `/var/lib/mlocate/mlocate.db’: 没有那个文件或目录
updatedb更新数据库
[root@localhost ~]# updatedb
[root@localhost ~]# locate we
/etc/cron.weekly
/etc/pm/power.d
/etc/selinux/targeted/active/modules/100/callweaver
/etc/selinux/targeted/active/modules/100/webadm
/etc/selinux/targeted/active/modules/100/webalizer
/etc/selinux/targeted/active/modules/100/callweaver/cil
/etc/selinux/targeted/active/modules/100/callweaver/hll
对于新建的文件
我们发现 搜索不了。
原因是 locate命令搜索的是 /var/lib/mlocate 下的mlocate.db数据库
这个数据库不是实时更新的,所以我们需要更新下数据库;
updatedb一下 在搜索就能搜素到了。
locate优点是 搜索速度快 ,缺点是只能按文件名搜索;
更新数据库配置文件/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”
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
“/etc/updatedb.conf” 4L, 513C
这里PRUNE_BIND_MOUNTS=”yes”开启搜索限制
PRUNEFS = 搜索时,不搜索的文件系统
PRUNENAMES = 搜索时,不搜索的文件类型
PRUNEPATHS = 搜索时,不搜索的路径
比如这里的tmp路径的文件 默认配置是搜索不到的;