继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Linux每天学习一个命令之locate命令

小灰灰heart
关注TA
已关注
手记 14
粉丝 36
获赞 629
locate  [-ir]  keywords

-i:表示忽略大小写
-r:表示后面跟正则表达式

下面来看看例子:

[root@localhost shell]# locate apache
/etc/selinux/targeted/modules/active/modules/apache.pp
/usr/lib/python2.7/site-packages/sos/plugins/apache.py
/usr/lib/python2.7/site-packages/sos/plugins/apache.pyc
/usr/lib/python2.7/site-packages/sos/plugins/apache.pyo
/usr/share/openscap/schemas/oval/5.10/apache-definitions-schema.xsd
/usr/share/openscap/schemas/oval/5.10/apache-system-characteristics-schema.xsd
/usr/share/openscap/schemas/oval/5.10.1/apache-definitions-schema.xsd
/usr/share/openscap/schemas/oval/5.10.1/apache-system-characteristics-schema.xsd
/usr/share/openscap/schemas/oval/5.11/apache-definitions-schema.xsd
/usr/share/openscap/schemas/oval/5.11/apache-system-characteristics-schema.xsd
/usr/share/openscap/schemas/oval/5.3/apache-definitions-schema.xsd
/usr/share/openscap/schemas/oval/5.3/apache-system-characteristics-schema.xsd
[root@localhost shell]# locate -i  apache
/etc/selinux/targeted/modules/active/modules/apache.pp
/usr/lib/python2.7/site-packages/sos/plugins/apache.py
/usr/lib/python2.7/site-packages/sos/plugins/apache.pyc
/usr/lib/python2.7/site-packages/sos/plugins/apache.pyo
/usr/share/doc/clucene-core-2.3.3.4/APACHE.license
/usr/share/doc/python-cryptography-0.8.2/LICENSE.APACHE
/usr/share/doc/wqy-microhei-fonts-0.2.0/LICENSE_Apache2.txt
/usr/share/openscap/schemas/oval/5.10/apache-definitions-schema.xsd
/usr/share/openscap/schemas/oval/5.10/apache-system-characteristics-schema.xsd
/usr/share/openscap/schemas/oval/5.10.1/apache-definitions-schema.xsd
/usr/share/openscap/schemas/oval/5.10.1/apache-system-characteristics-schema.xsd

由上面的例子可以看出默认和加-i参数的区别。
locate命令查找速度很快,但是有限制的,因为locate查找的数据是由已创建的数据库/var/lib/mlocate/里面的数据查找得到的,不用从硬盘上去访问数据,所以他的查找速度很快。
但是不准确,因为数据库的创建默认是每天执行一次(不同的Linux distrution是不同的),所以你刚刚安装的软件是查不到的,有办法解决这个问题,就是手动更新数据库即可,直接执行updatedb命令即可,更新的时候时间可能会很长。

最后总结一下:
locate:是依据/var/lib/mlocate/数据库中的信息来查找数据的
updatedb:是根据/etc/update.conf的设置去查找硬盘中的文件名,并跟新/var/lib/mlocate内的信息

打开App,阅读手记
28人推荐
发表评论
随时随地看视频慕课网APP