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