LoginSignup
60
47

More than 5 years have passed since last update.

grepで特定のディレクトリを除外する

Posted at

特定の文字列を検索したくて

grep -rn 'hoge' ./

ってする事ありますよね?

今まで

バージョン管理とかしていると、.svnや.gitの中のファイルまで結果に出てきたりして、欲しい情報が埋もれてしまって読めない。
そこで、-vを駆使したり、findの結果を引っ張ってきて色々してみたりという事をしていました。

久しぶりにググった

で、ふとググってみたら・・・
grepで特定ディレクトリを除外して再起検索

grep -r --exclude-dir=kernel PASSWORD *

--exclude-dirオプションはGNU grep 2.5.2から追加された

とあるじゃないですか!!
知らなかったー(>_<

結論

grep -rn 'hoge' ./ --exclude-dir=.git

便利ですね〜。
ところで、僕の環境だと、man grepにこのオプション無いんですけど、なんででしょ?

60
47
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
60
47