zoukankan      html  css  js  c++  java
  • Linux命令之locate命令

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

  • 相关阅读:
    2013第2周四晴
    2012第53周&2013第1周日
    2013周六雪转阴
    2013年第二周日生活整理
    php技术–php中感叹号!和双感叹号!!的用法(三元运算)
    laravel拓展validator验证
    laravel 5 自定义全局函数,怎么弄呢?
    Laravel 清空配置缓存
    网上很多laravel中cookie的使用方法。
    艾伟也谈项目管理,给敏捷团队中的架构师的10个建议 狼人:
  • 原文地址:https://www.cnblogs.com/leeyongbard/p/9519807.html
Copyright © 2011-2022 走看看