path にスペースを含むケースで find + xargs grep を使う
find の結果出力される path に空白が含まれている場合、後続の grep で path を正しく解釈することができずにエラーとなることがある。
Gemini にお伺いを立てて以下で対応できた。
code:_
find . -name '{file-pattern}' -print0 | xargs -0 grep '{text-pattern}'
Gemini の回答
1. find コマンドで -print0 オプションを使用する
find コマンドの -print0 オプションは、ファイル名に空白や改行などの特殊文字が含まれていても、それらを1つの引数として扱います。
code: man find
-print0
This primary always evaluates to true. It prints the pathname of the current file to standard output, followed by an ASCII NUL character (character code 0).