linux命令之locate

作用:

  locate(locate) 命令用來查找文件或目錄, locate命令要比find -name快得多,原因在於它不搜索具體目錄,而是搜索一個數據庫/var/lib/mlocate/mlocate.dbLinux系統自動創建這個數據庫,並且每天自動更新一次,因此,我們在用whereis和locate 查找文件時,有時會找到已經被刪除的數據,或者剛剛建立文件,卻無法查找到,原因就是因爲數據庫文件沒有被更新。爲了避免這種情況,可以在使用locate之前,先使用updatedb命令,手動更新數據庫。整個locate工作其實是由四部分組成的:

  1. /usr/bin/updatedb   主要用來更新數據庫,通過crontab自動完成的

  2. /usr/bin/locate         查詢文件位置

  3. /etc/updatedb.conf   updatedb的配置文件

  4. /var/lib/mlocate/mlocate.db  存放文件信息的文件

參數:

-b, --basename         match only the base name of path names
  -c, --count            只輸出找到的數量
  -d, --database DBPATH  使用DBPATH指定的數據庫,而不是默認數據庫 /var/lib/mlocate/mlocate.db
  -e, --existing         only print entries for currently existing files
  -L, --follow           follow trailing symbolic links when checking file existence (default)
  -h, --help             顯示幫助
  -i, --ignore-case      忽略大小寫
  -l, --limit, -n LIMIT  limit output (or counting) to LIMIT entries
  -m, --mmap             ignored, for backward compatibility
  -P, --nofollow, -H     don't follow trailing symbolic links when checking file existence
  -0, --null             separate entries with NUL on output
  -S, --statistics       don't search for entries, print statistics about eachused database
  -q, --quiet            安靜模式,不會顯示任何錯誤訊息
  -r, --regexp REGEXP    使用基本正則表達式
      --regex            使用擴展正則表達式
  -s, --stdio            ignored, for backward compatibility
  -V, --version          顯示版本信息
  -w, --wholename        match whole path name (default)

實例

[root@cs70-moban ~]# locate cat

/usr/share/mime/application/vnd.ms-word.template.macroEnabled.12.xml
/usr/share/mime/application/vnd.ms-works.xml
/usr/share/mime/application/vnd.ms-wpl.xml
/usr/share/mime/application/vnd.oasis.opendocument.chart-template.xml
/usr/share/mime/application/vnd.oasis.opendocument.chart.xml
/usr/share/mime/application/vnd.oasis.opendocument.database.xml
/usr/share/mime/application/vnd.oasis.opendocument.formula-template.xml
/usr/share/mime/application/vnd.oasis.opendocument.formula.xml
/usr/share/mime/application/vnd.oasis.opendocument.graphics-flat-xml.xml
/usr/share/mime/application/vnd.oasis.opendocument.graphics-template.xml
/usr/share/mime/application/vnd.oasis.opendocument.graphics.xml
/usr/share/mime/application/vnd.oasis.opendocument.image.xml
/usr/share/mime/application/vnd.oasis.opendocument.presentation-flat-xml.xml
/usr/share/mime/application/vnd.oasis.opendocument.presentation-template.xml
/usr/share/mime/application/vnd.oasis.opendocument.presentation.xml
/usr/share/mime/application/vnd.oasis.opendocument.spreadsheet-flat-xml.xml
/usr/share/mime/application/vnd.oasis.opendocument.spreadsheet-template.xml
/usr/share/mime/application/vnd.oasis.opendocument.spreadsheet.xml
/usr/share/mime/application/vnd.oasis.opendocument.text-flat-xml.xml
/usr/share/mime/application/vnd.oasis.opendocument.text-master.xml
/usr/share/mime/application/vnd.oasis.opendocument.text-template.xml
/usr/share/mime/application/vnd.oasis.opendocument.text-web.xml
/usr/share/mime/application/vnd.oasis.opendocument.text.xml

發佈了71 篇原創文章 · 獲贊 2 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章