查找 | grep 在 Cygwin 中不起作用

jcu*_*bic 4 cygwin grep find

我已经安装了 cygwin,当我使用此命令搜索源代码时,没有任何显示,即使我在文件中有该字符串

$ echo foo > bar
$ find . -name '*' | grep foo
Run Code Online (Sandbox Code Playgroud)

什么都不显示。此命令在 GNU+Linux 上运行良好。

$ grep foo bar
Run Code Online (Sandbox Code Playgroud)

squ*_*org 9

find . -name  '*' # This will produce a list of *file names*
Run Code Online (Sandbox Code Playgroud)

然后您将文件名列表传递给grep标准输入,它将列表视为文本并搜索foo

你没有文件名,foo所以它什么都不返回。

要递归搜索文件以查找文件中的文本,您可以简单地使用

grep -R foo somefolder/
Run Code Online (Sandbox Code Playgroud)

  • @jcubic 如果您的命令 `find . -名称'*' | grep foo` 在 find 命令列出的文件中找到单词 foo 那么你的 Linux 坏了,你应该提交一个错误。 (4认同)