find

Linux において階層ディレクトリを対象に,ファイル名から検索を行うことができるコマンド。

基本的な使い方

いわゆる emacs のバックアップファイルを探す。

$ find . -name *~

emacs のバックアップファイルを削除する。

$ find . -name *~ -delete

.# で始まるファイル名のファイルを検索する。

$ find . -name ".#*"

exec オプション

CVS ディレクトリを削除する。

$ find . -name CVS -exec rm -r {} \;

最後の \; がないとエラーになる。

$ find . -name "_*" -exec rm -r {}
find: missing argument to `-exec'

検索対象がディレクトリであることを明示する。

$ find . -name "CVS" -type d -exec rm -rf {} \;

古いファイルを消す

100日以上古いファイルを消す。

$ find . -mtime +100 -exec rm {} \;

ディレクトリ階層下までファイル内検索

http://ryouchi.seesaa.net/article/103448362.html

  find . -print | xargs grep 'emacs' /dev/null
  find . -print | xargs grep 'emacs' /dev/null | less
  grep emacs -r .

find.txt · 最終更新: 2011/08/24 11:05 by Takuya Nishimoto
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0