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 ...
随机推荐
- 前端规范--eslint standard
https://github.com/standard/standard/blob/master/docs/RULES-zhcn.md
- IPERF 网络性能测试
Iperf 是一个网络性能测试工具.Iperf可以测试最大TCP和UDP带宽性能.Iperf具有多种参数和UDP特性,可以根据需要调整.Iperf可以报告带宽,延迟抖动和数据包丢失. Iperf 参数 ...
- [转载]PowerDesigner生成的ORACLE 建表脚本中去掉对象的双引号,设置大、小写
若要将 CDM 中将 Entity的标识符都设为指定的大小写,则可以这么设定: 打开cdm的情况下,进入Tools-Model Options-Naming Convention,把Name和Code ...
- SQL 语法笔记
➪SQL ➪基本类型 char / varchar / int / smallint / numeric / real, double precision / float ➪数据定义 create t ...
- Python+OpenCV图像处理(十三)—— Canny边缘检测
简介: 1.Canny边缘检测算子是John F. Canny于 1986 年开发出来的一个多级边缘检测算法. 2.Canny 的目标是找到一个最优的边缘检测算法,最优边缘检测的含义是: 好的检测- ...
- 事务 c#
事务->:事务是恢复和并发控制的基本单位 ->事务具有四个特性:原子性.隔离性.一致性.持久性.这四个特性通常称为ACID Begin transaction/tran --开始事务 ...
- GUID生成函数
/** * GUID生成函数 * @return string */function create_guid() { $charid = strtoupper(md5(uniqid(mt_rand() ...
- Python语言知识总结
1. 环境 1.1 Anaconda 抛弃python原生安装方式吧,使用Anaconda才是最省心的. 1.2 Miniconda Anaconda 太大了,Miniconda才是王道!下载链接:h ...
- centos6.5编译安装php7
1.安装依赖软件库: yum install -y libxml2-devel libtool* curl-devel libjpeg-devel libpng-devel freetype-deve ...
- Codeforces 834D The Bakery - 动态规划 - 线段树
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredient ...