这个问题似乎与 a specific programming problem, a software algorithm, or software tools primarily used by programmers 无关.如果您认为该问题将成为 another Stack Exchange site 上的主题,您可以发表评论,说明在哪里可以回答问题。
关闭 7 个月前。
社区审核了是否重新打开这个问题7个月前并关闭:
原始关闭原因未解决
如何使用 grep在 Linux 上只显示文件名(没有内联匹配)?
我通常使用类似的东西:
find . -iname "*php" -exec grep -H myString {} \;
我怎样才能获得文件名(带路径),但没有匹配项?我必须使用 xargs ?我没有在我的 grep 手册页上看到这样做的方法。
最佳答案
标准选项 grep -l
(即小写 L)可以做到这一点。
来自Unix standard :
-l
(The letter ell.) Write only the names of files containing selected
lines to standard output. Pathnames are written once per file searched.
If the standard input is searched, a pathname of (standard input) will
be written, in the POSIX locale. In other locales, standard input may be
replaced by something more appropriate in those locales.
在这种情况下,您也不需要 -H
。
https://stackoverflow.com/questions/6637882/