locate:基于事先构建好的索引库查找,速度比较快,但是不是实时的。有时候可能出现索引不到的情况
-b :只匹配路径中的基名
-c :统计出符合条件的数量
- 安装locate
[root@host test]# yum provides locate
已加载插件:fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
mlocate-0.26-8.el7.x86_64 : An utility for finding files by name #包名称
...
[root@host test]# yum install mlocate #安装这个就好了
- locate
[root@host test]# locate man1
/usr/local/apache/man/man1
/usr/local/apache/man/man1/ab.1
/usr/local/apache/man/man1/apxs.1
/usr/local/apache/man/man1/dbmmanage.1
/usr/local/apache/man/man1/htdbm.1
/usr/local/apache/man/man1/htdigest.1
......
- locate -b :只匹配基名
[root@host test]# locate -b man1
/usr/local/apache/man/man1
/usr/local/pcre/share/man/man1
/usr/local/share/man/man1
/usr/local/share/man/man1x
/usr/share/man/man1
...
/usr/share/man/pl/man1
/usr/share/man/pt_BR/man1
/usr/share/man/ru/man1
/usr/share/man/sv/man1
/usr/share/man/tr/man1
/usr/share/man/zh_CN/man1
/usr/share/man/zh_TW/man1
- locate -c:统计符合条件的数量
[root@host test]# locate -c man1
1086
[root@host test]# locate -b -c man1
24
注:如果是本次开机之后创建的文件,locate是否能找到
[root@host test]# touch 777999
[root@host test]# locate -c 777999 #此处显示是找不到的
0
注:系统周期性更新索引库。此时如果想要locate 查找,就需要手动更新索引库了
[root@host test]# updatedb
[root@host test]# locate -c 777999
1
[root@host test]# locate 777999
/root/test/777999
find:实时查找工具,速度较locate慢一些
注:find前面写过详细的,直接连接查看就可以了