R.A. Epigonos et al.

[linux] ファイル検索するならfindの前にlocate

ファイルが何処にあるか検索するときに、findを使うと時間がかかりすぎる場合がある。そんなときにlocateを使う。これを使うと高速に検索できるが、実際はあるのにヒットしない場合も有る。

検索したいファイル名を引数に与えるだけでよい。

$ locate curses.h
/usr/include/curses.h
/usr/include/ncurses.h
/usr/include/ncursesw/curses.h
/usr/include/ncursesw/ncurses.h

locateはupdatedbコマンドでデータベース化されたファイル名とファイルフルパスを参照している。データベース化するルールはdebian squeezeの場合、/etc/updatedb.confの設定ファイルに書かれている。この内容を確認すると、データベース化しないデータベースパス、ファイルシステム、ファイル名が設定されていることがわかる。

$ locate updatedb.conf
/etc/updatedb.conf
/usr/share/man/man5/updatedb.conf.5.gz
$ cat /etc/updatedb.conf
PRUNE_BIND_MOUNTS="yes"
# PRUNENAMES=".git .bzr .hg .svn"
PRUNEPATHS="/tmp /var/spool /media"
PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre_lite tmpfs usbfs udf fuse.glusterfs fuse.sshfs"

updatedbは一日に1回走るので、新しいファイルはデータベース化されていない。crontで走らされるスクリプトは/etc/cron.daily/mlocateである。

リファレンス

  1. locate - Google 検索
  2. /etc/updatedb.conf - Google 検索
  3. ファイル/ディレクトリの検索
  4. 個人的Linux: /etc/updatedb.confの設定
  5. Debian -- squeeze の mlocate パッケージに関する詳細
  6. /etc/cron.daily/mlocate - Google 検索
  7. ファイル名検索コマンドlocateのデータベースの更新
  8. 【 locate 】 ファイルを高速に検索する - Linuxコマンド集:ITpro
  9. 【 updatedb 】 locate用ファイル・データベースを更新する - Linuxコマンド集:ITpro
  10. Linux: locate (Japanese)
  11. UNIXの部屋 コマンド検索:locate (*BSD/Linux)

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2009-12-25T14:18:43+09:00
  2. Modified: 2009-12-25T14:18:43+09:00
  3. Generated: 2023-08-27T23:09:13+09:00