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. Convolutional Patch Networks with Spatial Prior for Road Detection and Urban Scene Understanding

    Convolutional Patch Networks with Spatial Prior for Road Detection and Urban Scene Understanding 深度学 ...

  2. static 关键字的使用,静态和非静态类的区别

    直接以一个例子说明: using System; using System.Collections.Generic; using System.Diagnostics; using System.IO ...

  3. 设置VisualSVN在提交修改时必须输入一定数量的备注信息

    我发现在使用SVN中,提交时,很多人不习惯填写备注信息,虽然在培训中.平时使用时多次提醒备注信息的好处,但是效果不大,每次提交时还是不写,或者随便写两字. 所以很有必要通过系统设置强制填写足够数量的备 ...

  4. Verilog 浮点数运算模块

    算法中常常会到浮点数运算,而浮点数的处理常常是Verilog初学中常常遇到的问题.以下将就一个简单的例子说明Verilog中浮点数运算处理. 在JPEG图像压缩时遇到色彩空间变换的问题,将YCbCr转 ...

  5. 50 years of Computer Architecture: From the Mainframe CPU to the Domain-Specific TPU and the Open RISC-V Instruction Set

    1.1960年代(大型机) IBM发明了具有二进制兼容性的ISA——System/360,可以兼容一系列的8到64位的硬件产品,而不必更换操作系统.这是通过微编程实现的,每个计算机模型都有各自的ISA ...

  6. Eclipse配置总结

       按照公司要求,开发环境使用Eclipse Juno版本,需要安装maven插件和RTC插件.      经过一下午的尝试,总结经验教训:        1.eclipse安装maven的m2ec ...

  7. 安装SQLserver 2014(For AlwaysOn)

    SQLserver 2014 AlwaysOn在SQLserver 2012的基础之上,进行了非常大程度的添加.如能够通过"加入 Azure 副本向导"简化了用于 AlwaysOn ...

  8. dedecms单独调用指定文章

    {dede:arclist idlist='指定ID' limit='0,1'} <a href="[field:arcurl/]">[field:title/]< ...

  9. 织梦DedeCMS自定义表单提交成功后返回当前页面的教程

    织梦的自定义表单制作的留言,报名等功能,提交成功后会自动返回到首页,那么如何让它返回到当前页面呢? 方法如下: 打开plus/diy.php文件 找到 showmsg($bkmsg, $goto); ...

  10. 一、任天堂ns (Nintendo Switch) 上手

    公司不方便回家详解做个博客非专业评测~