標籤:style blog http color 使用 strong
全文節選翻譯自:http://linux-blog.org/finding-files-with-locate/
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資料庫裡面的索引!