• 技术文章 >运维 >linux运维

    locate指令是什么

    coldplay.xixicoldplay.xixi2020-11-02 14:46:14原创3130

    locate指令是用来查找文件或目录, locate命令要比【find -name】快得多,原因在于它不搜索具体目录,而是搜索一个数据库,语法是【locate [OPTION]... [PATTERN]...】。

    locate指令:

    1、命令简介

    locate(locate) 命令用来查找文件或目录。 locate命令要比find -name快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/mlocate/mlocate.db 。这个数据库中含有本地所有文件信息。Linux系统自动创建这个数据库,并且每天自动更新一次,因此,我们在用whereis和locate 查找文件时,有时会找到已经被删除的数据,或者刚刚建立文件,却无法查找到,原因就是因为数据库文件没有被更新。为了避免这种情况,可以在使用locate之前,先使用updatedb命令,手动更新数据库。整个locate工作其实是由四部分组成的:

    2、用法

    locate [OPTION]... [PATTERN]...

    3、选项

      -b, --basename         match only the base name of path names
      -c, --count            只输出找到的数量
      -d, --database DBPATH  使用DBPATH指定的数据库,而不是默认数据库 /var/lib/mlocate/mlocate.db
      -e, --existing         only print entries for currently existing files
      -L, --follow           follow trailing symbolic links when checking file existence (default)
      -h, --help             显示帮助
      -i, --ignore-case      忽略大小写
      -l, --limit, -n LIMIT  limit output (or counting) to LIMIT entries
      -m, --mmap             ignored, for backward compatibility
      -P, --nofollow, -H     don't follow trailing symbolic links when checking file existence
      -0, --null             separate entries with NUL on output
      -S, --statistics       don't search for entries, print statistics about eachused database
      -q, --quiet            安静模式,不会显示任何错误讯息
      -r, --regexp REGEXP    使用基本正则表达式
          --regex            使用扩展正则表达式
      -s, --stdio            ignored, for backward compatibility
      -V, --version          显示版本信息
      -w, --wholename        match whole path name (default)

    4、示例

    示例1: 搜索etc目录下所有以my开头的文件

    [root@cent6 lib]# locate /etc/my
    /etc/my.cnf

    示例2:新增的文件无法locate,使用updatedb

    [root@cent6 ~]# touch new.txt
    [root@cent6 ~]# locate new.txt
    [root@cent6 ~]# updatedb
    [root@cent6 ~]# locate new.txt
    /root/new.txt

    示例3:updatedb的配置文件/etc/updatedb.conf

    [root@cent6 ~]# cat /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"

    相关学习推荐:linux视频教程

    以上就是locate指令是什么的详细内容,更多请关注php中文网其它相关文章!

    声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    专题推荐:locate指令
    上一篇:vim命令是什么 下一篇:linux cd命令怎么用?
    大前端线上培训班

    相关文章推荐

    • 一张图带你缕清linux目录结构!• 一文讲解Linux服务器如何部署apache和php• 唠唠到底是什么阻碍了Linux桌面的发展?• 一文讲解windows怎么连接Linux桌面?• 四步搞定Linux git命令免输密码的设置

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网