首页 / LINUX / Linux命令之locate命令
Linux命令之locate命令
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Linux命令之locate命令,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2818字,纯文字阅读大概需要5分钟。
内容图文
![Linux命令之locate命令](/upload/InfoBanner/zyjiaocheng/1067/52f43e06166346e5afcd9948b59d6878.jpg)
1.locate
locate 命令是文件搜索命令,它的搜索速度比 find 命令更快,原因在于它不搜索具体目录,
而是搜索一个数据库,这个数据库包含本地所有文件信息。Linux系统自动创建这个数据库,
并且每天自动更新一次,所以使用 locate 这个命令查不到最新变动过的文件。为了避免这种情况
可以在使用locate之前,先使用 updatedb 命令,手动更新数据库。
命令格式:
locate [文件名]
#Example01 在var目录下添加index.hml
[root@VM_81_181_centos /]# locate index.html /usr/share/doc/HTML/index.html /usr/share/doc/cyrus-sasl-lib-2.1.23/index.html /usr/share/doc/db4-utils-4.7.25/utility/index.html /usr/share/doc/gamin-0.1.10/index.html /usr/share/doc/python-babel-0.9.4/doc/index.html /usr/share/doc/python-babel-0.9.4/doc/api/identifier-index.html /usr/share/doc/python-babel-0.9.4/doc/api/index.html /usr/share/doc/python-babel-0.9.4/doc/api/since-index.html /usr/share/doc/python-iniparse-0.3.1/index.html /usr/share/doc/python-jinja2-2.2.1/ext/django2jinja/templates/index.html /usr/share/doc/python-jinja2-2.2.1/html/genindex.html /usr/share/doc/python-jinja2-2.2.1/html/index.html /usr/share/doc/python-pygments-1.1.1/docs/build/index.html /usr/share/doc/rsyslog-5.8.10/index.html /usr/share/doc/udev-147/writing_udev_rules/index.html
发现并没有搜索到/var/index.html
使用 updatedb 命令:
[root@VM_81_181_centos /]# updatedb [root@VM_81_181_centos /]# locate index.html /usr/share/doc/HTML/index.html /usr/share/doc/cyrus-sasl-lib-2.1.23/index.html /usr/share/doc/db4-utils-4.7.25/utility/index.html /usr/share/doc/gamin-0.1.10/index.html /usr/share/doc/python-babel-0.9.4/doc/index.html /usr/share/doc/python-babel-0.9.4/doc/api/identifier-index.html /usr/share/doc/python-babel-0.9.4/doc/api/index.html /usr/share/doc/python-babel-0.9.4/doc/api/since-index.html /usr/share/doc/python-iniparse-0.3.1/index.html /usr/share/doc/python-jinja2-2.2.1/ext/django2jinja/templates/index.html /usr/share/doc/python-jinja2-2.2.1/html/genindex.html /usr/share/doc/python-jinja2-2.2.1/html/index.html /usr/share/doc/python-pygments-1.1.1/docs/build/index.html /usr/share/doc/rsyslog-5.8.10/index.html /usr/share/doc/udev-147/writing_udev_rules/index.html /var/index.html
2.当在某些目录下创建文件,然后更新数据库之后,并不能使用 locate 命令查找到
原因是系统在更新数据库的配置文件中,设置了一些限制,所以,搜索不到,输入以下命令可以看到:
[root@VM_81_181_centos lib]# 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 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"
PRUNE_BIND_MOUNTS = “yes” 表示开启搜索限制,如果为’no’则表示不开启搜索限制;
PRUNEFS = 表示搜索时,不搜索的文件系统;
PRUNENAMES = 表示搜索时,不搜索的文件类型;
PRUNEPATHS = 表示搜索时,不搜索的路径;
不只locate命令遵循搜索限制,whereis与which也遵循
原文:https://www.cnblogs.com/leeyongbard/p/9519807.html
内容总结
以上是互联网集市为您收集整理的Linux命令之locate命令全部内容,希望文章能够帮你解决Linux命令之locate命令所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。