Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

locate 指令快速定位檔案:資料庫原理、updatedb 更新、參數詳解、與 find 差異比較

編輯:關於 Linux

locate 透過預建索引資料庫(/var/lib/mlocate/mlocate.db)秒級搜尋檔名,不即時掃描磁碟,速度遠快於 find。

核心機制

  • updatedb 每日自動執行(cron),掃描全盤建立索引。
  • 新建/重命名檔案未更新資料庫前無法搜尋到。
  • 手動更新:sudo updatedb。

常用參數

  • -i:忽略大小寫。
  • -n N:最多顯示 N 筆。
  • -r:正規表示式搜尋。
  • -e:排除指定路徑。
  • -d:指定資料庫路徑。
  • -q:安靜模式(隱藏錯誤)。
  • -S:顯示資料庫統計資訊。

範例

  • locate *.conf:找所有 .conf 檔。
  • locate -i readme:大小寫不敏感找 README。
  • locate -n 10 passwd:前 10 筆含 passwd 的路徑。

適合「知道檔名約略關鍵字、需快速定位路徑」場景;需即時、依屬性/內容搜尋請用 find。

上一頁12下一頁共2頁

Copyright © Windows教程網 All Rights Reserved