locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案。

    (1)用法:

  用法:  Locate  [选项] [参数]

    (2)功能:

功能:  在mlocate数据库中搜索条目,用来快速查找文件或目录

    (3)选项参数:

1) -d<目录>或--database=<目录>:            指定数据库所在的目录

2) -i, --ignore-case                    匹配模式时忽略大小写区别

3) --help:                          显示帮助

4) --version:                        显示版本信息

5) -d, --database DBPATH                    用 DBPATH 替代默认的数据库(/var/lib/mlocate/mlocate.db)

    (4)实例:

1)[root@localhost Documents]# loacte less1            在各个目录下查找名为less1的这个文件或者文件夹

[root@localhost Documents]# ll
总用量
-rw-r--r--. root root 5月 : head_text
-rw-r--r--. root root 5月 : less1
-rw-r--r--. root root 5月 : less2
-rw-r--r--. root root 5月 : tail_text
-rw-r--r--. root root 5月 : tempory
[root@localhost Documents]# slocate less1 //经验证,已经没有slocate这个命令
bash: slocate: 未找到命令...
相似命令是: 'locate'
[root@localhost Documents]# loacte less1
bash: loacte: 未找到命令...
相似命令是: 'locate'

2)[root@localhost Documents]# locate Documents             如果是搜索的是文件夹的名称,则默认会先显示该文件夹及以下的各个文件及文件夹

[root@localhost Documents]# locate Documents
/home/sunjimeng/Documents
/home/sunjimeng/Documents/head_text
/home/sunjimeng/Documents/less1
/home/sunjimeng/Documents/less2
/home/sunjimeng/Documents/tail_text
/home/sunjimeng/Documents/tempory
/usr/share/dbus-/services/org.gnome.Documents.GDataMiner.service
/usr/share/dbus-/services/org.gnome.Documents.SearchProvider.service
/usr/share/dbus-/services/org.gnome.Documents.ZpjMiner.service
/usr/share/glib-2.0/schemas/org.gnome.Documents.enums.xml

3)[root@localhost Documents]# locate newlocate 和updatedb                 为了避免新建的文件夹找不到,可以立即更新数据库(updatedb命令)                   

[root@localhost Documents]# touch newlocate                          //新建文件
[root@localhost Documents]# ll                       //已经存在
总用量
-rw-r--r--. root root 5月 : head_text
-rw-r--r--. root root 5月 : less1
-rw-r--r--. root root 5月 : less2
-rw-r--r--. root root 5月 : newlocate
-rw-r--r--. root root 5月 : tail_text
-rw-r--r--. root root 5月 : tempory
[root@localhost Documents]# locate newlocate //但并找不到
[root@localhost Documents]# updatedb                   //更新数据库
[root@localhost Documents]# locate newlocate             //待计算机反应2秒后,再执行locate命令,就能找到了
/home/sunjimeng/Documents/newlocate

4)查找指定目录下的某个文件,也可以用通配符

[root@localhost /]# locate /home/sunjimeng/Documents/*e
/home/sunjimeng/Documents/newlocate

5)[root@localhost /]# locate -i /home/sunjimeng/Documents/*Cate                 在使用通配符时忽略大小写

[root@localhost /]# locate -i /home/sunjimeng/Documents/*Cate
/home/sunjimeng/Documents/newlocate
[root@localhost /]# locate /home/sunjimeng/Documents/*Cate
[root@localhost /]#

6)[root@localhost /]# locate /home/sunjimeng/Documents/le                         寻找以特定字符串开头的文件或文件夹

[root@localhost /]# locate /home/sunjimeng/Documents/le                                    //不加通配符也可以
/home/sunjimeng/Documents/less1
/home/sunjimeng/Documents/less2
[root@localhost /]# locate /home/sunjimeng/Documents/le*
/home/sunjimeng/Documents/less1
/home/sunjimeng/Documents/less2
[root@localhost /]#

7)[root@localhost Documents]# locate --help

[root@localhost Documents]# locate --help
Usage: locate [OPTION]... [PATTERN]...
Search for entries in a mlocate database. -A, --all only print entries that match all patterns
-b, --basename match only the base name of path names
-c, --count only print number of found entries
-d, --database DBPATH use DBPATH instead of default database (which is
/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 print this help
-i, --ignore-case ignore case distinctions when matching patterns
-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
-, --null separate entries with NUL on output
-S, --statistics don't search for entries, print statistics about each
used database
-q, --quiet report no error messages about reading databases
-r, --regexp REGEXP search for basic regexp REGEXP instead of patterns
--regex patterns are extended regexps
-s, --stdio ignored, for backward compatibility
-V, --version print version information
-w, --wholename match whole path name (default) 将 bug 报告给 mitr@redhat.com.

    (5)其他:

说明:

locate命令其实是find -name的另一种写法,但是要比后者快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/locatedb,这个数据库中含有本地所有文件信息。Linux系统自动创建这个数据库,并且每天自动更新一次,所以使用locate命令查不到最新变动过的文件。为了避免这种情况,可以在使用locate之前,先使用updatedb命令,手动更新数据库。

locate命令可以在搜寻数据库时快速找到档案,数据库由updatedb程序来更新,updatedb是由cron daemon周期性建立的,locate命令在搜寻数据库时比由整个由硬盘资料来搜寻资料来得快,但较差劲的是locate所找到的档案若是最近才建立或 刚更名的,可能会找不到,在内定值中,updatedb每天会跑一次,可以由修改crontab来更新设定值。(etc/crontab)

locate指定用在搜寻符合条件的档案,它会去储存档案与目录名称的数据库内,寻找合乎范本样式条件的档案或目录录,可以使用特殊字元(如”*” 或”?”等)来指定范本样式,如指定范本为kcpa*ner, locate会找出所有起始字串为kcpa且结尾为ner的档案或目录,如名称为kcpartner若目录录名称为kcpa_ner则会列出该目录下包括 子目录在内的所有档案。

每天一个Linux命令(18)loacte命令的更多相关文章

  1. 显示器 Linux 性能 18 (一个命令行工具传递)

    对于系统和网络管理员来说每天监控和调试Linux系统的性能问题是一项繁重的工作.在IT领域作为一名Linux系统的管理员工作5年后,我逐渐认识到监控和保持系统启动并执行是多么的不easy.基于此原因. ...

  2. 每天一个linux命令(18):find 命令概览

    Linux 下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.由于find具有强大的功能,所 以它的选项也很多,其中大部分选项都值得我们 ...

  3. 每天一个Linux命令:whereis(18)

    whereis whereis命令用来定位指令的二进制程序.源代码文件和man手册页等相关文件的路径. whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数- ...

  4. 每天一个 Linux 命令(21):find命令之xargs

    在使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行.但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出 ...

  5. 每天一个linux命令(46):vmstat命令

    vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动进行监控.他是对系统的整体情况进行统计,不足之处是无法对某个进程进行深 ...

  6. 每天一个linux命令目录

    出处:http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html 开始详细系统的学习linux常用命令,坚持每天一个命令,所以这个系列为每 ...

  7. 每天一个 Linux 命令(20):find命令之exec

    find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了. exec解释: -exec  参数后面跟的是command ...

  8. 每天一个linux命令(58):telnet命令

    telnet命令通常用来远程登录.telnet程序是基于TELNET协议的远程登录客户端程序.Telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式.它为用户 ...

  9. 每天一个linux命令(44):top命令

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法.top是一个动态显示过程,即可以通过用户按键来不断刷新 ...

  10. 每天一个linux命令(43):killall命令

    Linux系统中的killall命令用于杀死指定名字的进程(kill processes by name).我们可以使用kill命令杀死指定进程PID的进程,如果要找到我们需要杀死的进程,我们还需要在 ...

随机推荐

  1. LeetCode :: Sum Root to Leaf Numbers [tree、dfs]

    Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...

  2. Mac下安装LNMP(Nginx+PHP5.6)环境(转)

    安装Homebrew 最近工作环境切换到Mac,所以以OS X Yosemite(10.10.1)为例,记录一下从零开始安装Mac下LNMP环境的过程 确保系统已经安装xcode,然后使用一行命令安装 ...

  3. SpringCloud系列五:为Eureka Server添加用户认证及元数据

    1. 回顾 上一篇博客讲解了Eureka集群及将微服务注册到集群上.在前面的讲解中,Eureka Server都是允许匿名访问的,本次将讲解如何构建一个需要登录才能访问的Eureka Server. ...

  4. Swagger跨域访问

    我们用springboot开发完后,需要前端vue用swagger跨域,默认是不能跨域的,所以需要我们后台设置跨域访问,将下面代码完整复制即可. 在springboot项目中新建class : Cor ...

  5. 查看Tomcat状态页,管理app,主机管理

    Server Status 通过点击这个按钮我们可以查看Tomcat的状态,点击,弹出403错误页面 通过查看官方文档 因此,创建manager.xml # cat /usr/local/tomcat ...

  6. iOS ZipArchive文件解压缩

    ZipArchive可以用于iOS中文件的解压缩 压缩文件的方法: //将工程中picture添加到左面111.zip压缩文件中 如果崩溃请更换压缩路径 -(void)testZipFile{ //压 ...

  7. CSS div固定顶端

    position: fixed;原来只需要这么一个设置就可以!

  8. C语言include预处理命令与多文件编译

    #include预处理命令几乎使我们在第一次接触C的时候就会碰到的预处理命令,可我现在还不怎么清楚,这次争取一次搞懂. 一.#include预处理指令的基本使用 预处理指令可以将别处的源代码内容插入到 ...

  9. (C#)为应用程式设定运行权限(System.Security类下的GenericIdentity,GenericPrincipal,PrincipalPermission)

    最近看书<编写高质量代码改善C#程序的157个建议>,知识点备忘: System.Security.Principal.GenericIdentity==>表示一般用户 System ...

  10. 多媒体开发之--- rtsp 中的H264 编码+打包+解码相关知识es、pes、ts...

    1)ES流(Elementary Stream): 也叫基本码流,包含视频.音频或数据的连续码流. 2)PES流(Packet Elementary Stream): 也叫打包的基本码流, 是将基本的 ...