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常用命令:more 命令
more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...
- 20165215 实验三 敏捷开发与XP实践
20165215 实验三 敏捷开发与XP实践 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:张家佳 学号:20165215 指导教师:娄嘉鹏 实验日期:2018年4月28日 实验时 ...
- 在Linux 中如何从进程相关的文件描述中恢复数据
在Linux中误删除了某个文件,但是 ps-ef|grep 文件名 发现某个进程还在使用该文件,那么可以通 过以下方式恢复文件. 例如:创建一个简单文件/tmp/test.txt, 随便向里面写点内容 ...
- Spring P命名空间 02
P命名空间 装配属性 使用<property> 元素为Bean 的属性装配值和引用并不太复杂.尽管如此,Spring 的命名空间p 提供了另一种Bean 属性的装配方式,该方式不需要配置如 ...
- Eloquent JavaScript #03# functions
索引: let VS. var 定义函数的几种方式 more... 1.作者反复用的side effect side effect就是对世界造成的改变,例如说打印某些东西到屏幕,或者以某种方式改变机器 ...
- centos 内存清理
在清理前内存使用情况 free -m 用以下命令清理内存 echo 1 > /proc/sys/vm/drop_caches 清理后内存使用情况再用以下命令看看. free –m 多出很多内存了 ...
- git获取一个版本相对于另一个版本新增,修改,删除的文件
git diff --name-status 00ef237ef0f0a4b8bd9609c2b6d570472028212d abf13b4d58abbb05a7d494cdc205d025978a ...
- Golang原生sql操作Mysql数据库增删改查
Golang要操作mysql数据库,首先需要在当期系统配置GOPATH,因为需要使用go get命令把驱动包下载到GOPATH下使用. 首先配置好你的GOPATH,执行以下命令,下载安装mysql驱动 ...
- django加载静态文件
在一个网页中,不仅仅只有一个 html 骨架,还需要 css 样式文件. js 执行文件以及一些图片等,因此在 DTL 中加载静态文件是一个必须要解决的问题.在 DTL 中,使用 static 标签来 ...
- GitHub客户端使用
GitHub客户端使用 我们今天先讲解一下Github for windows(客户端)的使用方法,之后我们会以一个实例一步一步的来讲解Github. Github for windows(客户端)是 ...