小编典典

如何在 Linux 上使用 grep 仅显示文件名?

all

如何在 Linux 上使用grep仅显示文件名(无内联匹配)?

我通常使用类似的东西:

find . -iname "*php" -exec grep -H myString {} \;

我怎样才能得到文件名(带路径),但没有匹配项?我必须使用xargs吗?我没有在我的
grep 手册页上看到这样做的方法。


阅读 752

收藏
2022-02-25

共1个答案

小编典典

标准选项grep -l(即小写 L)可以做到这一点。

Unix 标准

-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在这种情况下你也不需要。

2022-02-25