歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux使用locate命令定位文件

Linux使用locate命令定位文件

日期:2017/2/28 14:29:46   编辑:Linux教程

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命令的強大不僅僅用於查找文件,其搜索磁盤的時候是需要時間的。那麼有沒有快速定位的方法呢?

Linux下定位命令總結 http://www.linuxidc.com/Linux/2012-10/72430.htm

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數據庫裡面的索引!

Linux下find命令詳解 http://www.linuxidc.com/Linux/2011-08/40669.htm

文本查找利器find的使用 http://www.linuxidc.com/Linux/2014-03/97559.htm

功能強大的find命令 http://www.linuxidc.com/Linux/2014-01/95236.htm

Linux系統find命令詳解 http://www.linuxidc.com/Linux/2014-06/103232.htm

Copyright © Linux教程網 All Rights Reserved