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也遵循

Linux命令之locate命令的更多相关文章

  1. Linux which/whereis/locate命令详解

    which 查看可执行文件的位置,从全局环境变量PATH里面查找对应的路径,默认是找 bash内所规范的目录 whereis 查看文件的位置,配合参数-b,用于程序名的搜索,从linux数据库查找. ...

  2. 常用linux命令:locate 命令

    locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了.在一般的 di ...

  3. linux常用命令(16)locate命令

    locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了.在一般的 di ...

  4. linux里添加locate命令

    在linux里使用和find一样的功能 例如 find -name xx 可以yum install mlocate 然后 updatedb 再使用locate xx  来查找xx文件

  5. Linux 命令中 which、whereis、locate 命令的用法

    which 命令 which 命令的作用是,在 PATH 变量指定的路径中搜索可执行文件的所在位置.它一般用来确认系统中是否安装了指定的软件. (1)命令格式 which 可执行文件名称 wherei ...

  6. Linux使用locate命令定位文件

    FIND命令 很多Linux用户喜欢使用find命令来查找文件,例如他们通常喜欢这样做: find / -name 'pattern' 确实find的强大功能不仅仅用来查找文件,它能用来定位更加细节的 ...

  7. Linux下相关查找文件命令(find locate which whereis type)

    以下内容摘自:http://blog.csdn.net/jessica1201/article/details/8139249 标注的内容为自己的补充: 我们经常需要在系统中查找一个文件,那么在lin ...

  8. Linux的五个查找命令find,locate,whereis,which,type

    Linux的五个查找命令 1. find 最常见且最强大的命令,可以查找任何文件. 格式 $ find   指定目录   指定条件   指定动作   指定目录: 所要搜索的目录及其子目录,默认当前目录 ...

  9. linux locate命令

    1.命令简介         locate(locate) 命令用来查找文件或目录. locate命令要比find -name快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/ml ...

随机推荐

  1. 【Alpha版本】冲刺阶段——Day1

    [Alpha版本]冲刺阶段--Day1 阅读目录 Alpha 阶段成员分工及任务量 团队成员贡献值的计算规则 明日任务 今日贡献量 站立式会议 TODOlist [Alpha 阶段成员分工及任务量] ...

  2. Spark With Mongodb 实现方法及error code -5, 6, 13127解决方案

    1.spark mongo 读取 val rdd = MongoSpark.builder().sparkSession(spark).pipeline(Seq(`match`(regex(" ...

  3. 查询在某一个时间段内的sql(oracel)

    ( to_char(t.TUIJIAN_TIME, 'yyyy-MM-dd') between   #{begin_time}   and #{end_time} )

  4. Django框架----路由系统、视图和模板(简单介绍)

    一.路由配置系统(urls) URL配置(URLconf)就像Django所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表: 你就是以这种方式告诉Django,对于这个URL ...

  5. 三张图搞懂JavaScript的原型对象与原型链 / js继承,各种继承的优缺点(原型链继承,组合继承,寄生组合继承)

    摘自:https://www.cnblogs.com/shuiyi/p/5305435.html 对于新人来说,JavaScript的原型是一个很让人头疼的事情,一来prototype容易与__pro ...

  6. Kattis之旅——Factovisors

    The factorial function, n! is defined thus for n a non-negative integer: 0! = 1 n! = n * (n-1)! (n & ...

  7. Oracle通过dblink连接MySQL

    需要把MySQL的一些数据同步到Oracle,用ETL工具太麻烦了,通过参考官方文档实现了oracle to mysql dblink.每次修改配置后,需要重启监听才能生效,或者 reload一下,确 ...

  8. Tensorflow学习笔记01

    Tensorflow官方网站:http://tensorflow.org/ 极客学院Tensorflow中文版:http://wiki.jikexueyuan.com/project/tensorfl ...

  9. SaaS的中年危机(转)

    如果说SaaS软件和人有什么地方很像的话,中年危机一定是其中一个.另一个是交税. 经常有人问我,春阳,你觉得xx SaaS公司怎么样? 如果这是一家成立2年以上的公司,我的回答多半是“活的不是那么滋润 ...

  10. Java字节码浅析(—)

    英文原文链接,译文链接,原文作者:James Bloom,译者:有孚 明白Java代码是如何编译成字节码并在JVM上运行的非常重要,这有助于理解程序运行的时候究竟发生了些什么.理解这点不仅能搞清语言特 ...