Linux使用locate命令定位檔案

來源:互聯網
上載者:User

標籤: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資料庫裡面的索引!




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.