Linux使用locate命令定位文件

系统 Linux
很多Linux用户喜欢使用find命令来查找文件,例如他们通常喜欢这样做:find / -name 'pattern'。确实find的强大功能不仅仅用来查找文件,它能用来定位更加细节的东西……

FIND命令

很多Linux用户喜欢使用find命令来查找文件,例如他们通常喜欢这样做:

find / -name 'pattern'

确实find的强大功能不仅仅用来查找文件,它能用来定位更加细节的东西,比如你想在某个目录下找到一些赋予其拥有者和管理员可写的权限( if you wanted to find files which are writable by both their owner and their group),可以这样做:

find / -perm -444 -perm /222 ! -perm /111

又或者你想看看在你的下载目录下的过去24小时之内被修改过的文件,

find /home/user/Downloads/ -mtime 0

find命令的强大不仅仅用于查找文件,其搜索磁盘的时候是需要时间的。那么有没有快速定位的方法呢?

LOCATE命令

在使用locate之前,你得确认系统是否安装了mlocate包,现在大多数Linux发行版都集成了此包。如果没有安装,可以访问mlocate主页(http://carolina.mff.cuni.cz/~trmac/blog/mlocate/下载安装。下载安装成功后,你需要执行一条命令为你的文件系统索引。否则你就得等到程序哪天自动执行了。

已root用户身份执行如下命令:

updatedb &

这条命令会后台更新你的mlocate数据库,这数据库包含了你的文件系统的索引(This updates the mlocate database that indexes your files and forks it to the background (the ‘&’ forks it to the background)。

等这条命令执行完了,你可以轻松的使用locate命令:

locate firefox | less

这会快速地定位有关firefox的文件、目录等等。速度也比find快,因为它读取的是mlocate数据库里面的索引!

原文链接:http://blog.csdn.net/hanszang/article/details/37994671

责任编辑:牛小雨 来源: csdn
相关推荐

2022-10-08 08:04:47

FindLinuxLocate

2009-08-04 08:44:56

linux find命linux find查找文件命令

2021-12-22 10:25:13

locateLinuxplocate

2011-07-27 17:30:40

iPhone Locate 定位

2019-12-17 09:00:48

split分割Linux文件Linux

2020-09-22 07:29:14

Linux stat

2021-09-10 10:35:25

Linuxstat命令文件系统

2018-11-12 09:30:49

Linux命令文件管理器

2018-05-09 12:27:34

Linux命令寻找文件

2022-08-17 12:35:26

Linux sed编辑器

2009-08-03 12:02:13

linux at命令linux at命令详使用案例

2018-04-28 09:12:42

Linux

2022-05-25 08:41:48

Linuxfd 命令文件

2009-12-23 10:58:58

Linux创建文件命令

2009-12-23 10:58:58

Linux创建文件命令

2010-03-18 16:38:39

Linux命令

2009-10-19 17:10:37

Linux文件命令

2012-05-10 08:55:11

Linuxuniq

2022-11-13 19:43:37

Linux

2024-01-03 15:35:56

Linux工具Tail命令
点赞
收藏

51CTO技术栈公众号