LoginSignup
10
9

More than 5 years have passed since last update.

指定した文字列を含むファイルを検索するコマンド

Posted at

指定した文字列が書かれているファイルを検索できるコマンド.

$ find ./ -type f -print | xargs grep 'hoge'

コマンドの詳細

  • find

ディレクトリの中を再帰的に検索する.

$ find ディレクトリ 検索条件 アクション

ディレクトリが./の場合は,今いるディレクトリ配下が検索対象.
検索条件が-type fの場合はファイルを検索.-type dとするとディレクトリを検索する.
アクションが-printの場合は,結果を標準出力.


  • |

「パイプ」と呼ばれ,左側のコマンドの標準出力を右側のコマンドに標準入力として渡す.


  • xargs

ファイル名の一覧を標準入力から受け取り,それらをコマンドの引数として渡す.


  • grep

ファイルや標準入力から正規表現でマッチする行を探し出す.

参考

【Linux】複数あるファイルの中から特定の文字列を検索するコマンド

10
9
0

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
10
9