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

如何使用 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/

相关文章:

python - 如何正确确定当前脚本目录?

linux - 定义带或不带导出的变量

python - 如何反转 x 或 y 轴

python - 在 Python 3 中 generator.next() 是可见的吗?

python - 连接两个一维 NumPy 数组

linux - 如何将输出重定向到文件和标准输出

python - Pandas 'count(distinct)' 等效

linux - 杀死分离的 screen session

linux - 在 Bash 脚本中通过管道传入/传出剪贴板

python - 下标序列时Python中的::(双冒号)是什么?