阻止 grep 解析自己的输出管道到文件

Stop grep from parsing its own output piped to file

我是这样使用 grep 的: grep -r "foo" * > output.txt

然而,grep 似乎不断从 output.txt 中获取无限增长的结果。我怎样才能防止这种情况发生?

一个解决方案是:

grep -r "foo" . > ../output.txt
                  ^^
            parent directory

参见 man grep。然后试试这个:

grep -r "foo" * --exclude=output.txt > output.txt