Linuxで複数のファイルの中身から特定の文字列を検索するコマンドのメモです。
対象となるファイルを絞れるように -name によるファイル名の条件も複数追加させてみました。
$ find ./ -type f -name file_A -o -name file_B -print | xargs grep "hogestr"
これで、ファイル名【file_A】と【file_B】を対象に、文字列【hogestr】のあるファイルを取得できます。
実行例
下記のような感じで出力されます。ファイル名も分かる。
$ find ./ -type f -name file_A -o -name file_B -print | xargs grep "hogestr" ./dir111/conf/file_B:hogestr ./dir112/conf/file_B:hogestr ./dir113/conf/file_A:hogestr ./dir114/conf/file_B:hogestr ./dir115/conf/file_A:hogestr