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也遵循
Linux命令之locate命令的更多相关文章
- Linux which/whereis/locate命令详解
which 查看可执行文件的位置,从全局环境变量PATH里面查找对应的路径,默认是找 bash内所规范的目录 whereis 查看文件的位置,配合参数-b,用于程序名的搜索,从linux数据库查找. ...
- 常用linux命令:locate 命令
locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了.在一般的 di ...
- linux常用命令(16)locate命令
locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法是先建立一个包括系统内所有档案名称及路径的数据库,之后当寻找时就只需查询这个数据库,而不必实际深入档案系统之中了.在一般的 di ...
- linux里添加locate命令
在linux里使用和find一样的功能 例如 find -name xx 可以yum install mlocate 然后 updatedb 再使用locate xx 来查找xx文件
- Linux 命令中 which、whereis、locate 命令的用法
which 命令 which 命令的作用是,在 PATH 变量指定的路径中搜索可执行文件的所在位置.它一般用来确认系统中是否安装了指定的软件. (1)命令格式 which 可执行文件名称 wherei ...
- Linux使用locate命令定位文件
FIND命令 很多Linux用户喜欢使用find命令来查找文件,例如他们通常喜欢这样做: find / -name 'pattern' 确实find的强大功能不仅仅用来查找文件,它能用来定位更加细节的 ...
- Linux下相关查找文件命令(find locate which whereis type)
以下内容摘自:http://blog.csdn.net/jessica1201/article/details/8139249 标注的内容为自己的补充: 我们经常需要在系统中查找一个文件,那么在lin ...
- Linux的五个查找命令find,locate,whereis,which,type
Linux的五个查找命令 1. find 最常见且最强大的命令,可以查找任何文件. 格式 $ find 指定目录 指定条件 指定动作 指定目录: 所要搜索的目录及其子目录,默认当前目录 ...
- linux locate命令
1.命令简介 locate(locate) 命令用来查找文件或目录. locate命令要比find -name快得多,原因在于它不搜索具体目录,而是搜索一个数据库/var/lib/ml ...
随机推荐
- Linux基础命令---pgrep
pgrep pgrep指令可以按名字或者其他属性搜索指定的进程,显示出进程的id到标准输出. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedo ...
- Linux基础命令---添加用户useradd
useradd 创建新的系统用户,useradd指令只能以管理员的身份运行,创建的用户都在“/etc/passwd”文件中.当不加-D参数,useradd指令使用命令列来指定新帐号的设定值and使用系 ...
- error C2504: “XXXXXXX”: 未定义基类
今天犯到了一个低级错误,记下来加深印象. 造成这一现象主要的原因是头文件相互包含,文件构成一个环形结构,从而编译时循环包含出错 如: AA.h中包含BB.h BB.h中包含CC.h CC.h中包含AA ...
- LoggerFactory.getLogger用法
使用指定类初始化日志对象,在日志输出的时候,可以打印出日志信息所在类 如:Logger logger = LoggerFactory.getLogger(com.lz.Test.class); ...
- Andriod post Api与返回值
vs后台api控制器 post接收参数----HttpContext.Current.Request.Params["account"].ToString() 返回值为对象返回, ...
- GoldenGate实时投递数据到大数据平台(2)- Cassandra
简介 GoldenGate是一款可以实时投递数据到大数据平台的软件,针对apache cassandra,经过简单配置,即可实现从关系型数据将增量数据实时投递到Cassandra,以下介绍配置过程. ...
- Linux下的Jmeter运行测试
本文主要介绍Jmeter脚本如何在Linux通过no GUI的方式运行.总共分三部分: 1.Linux下JDK的安装及环境变量的配置 2.Linux下Jmeter的安装及环境变量的配置 3.运行结果的 ...
- kafka数据可靠传输
再说复制Kafka 的复制机制和分区的多副本架构是Kafka 可靠性保证的核心.把消息写入多个副本可以使Kafka 在发生崩愤时仍能保证消息的持久性. Kafka 的主题被分为多个分区,分区是基本的数 ...
- django 上传文件及反馈信息
from django.shortcuts import render,HttpResponse from django.views import View from Fiskars.models i ...
- shell 脚本的时间差计算
在某个时间点上增加一段时间 将时间转为时间戳,然后增加时间 [root@~]# date +%s -d '2017-05-27 12:0:0' 1495857600 [root@ ~]# new_ti ...