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