如何在Linux上使用grep仅显示文件名? [英] How can I use grep to show just filenames on Linux?
本文介绍了如何在Linux上使用grep仅显示文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Linux上使用grep
仅显示文件名(无内联匹配)?
How can I use grep
to show just file-names (no in-line matches) on Linux?
我通常使用类似的东西:
I am usually using something like:
find . -iname "*php" -exec grep -H myString {} \;
如何仅获取文件名(带有路径),而没有匹配项?我必须使用xargs
吗?在我的grep
手册页上没有找到执行此操作的方法.
How can I just get the file-names (with paths), but without the matches? Do I have to use xargs
? I didn't see a way to do this on my grep
man page.
推荐答案
标准选项grep -l
(小写的L)可以做到这一点.
The standard option grep -l
(that is a lowercase L) could do this.
从 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
.
You also do not need -H
in this case.
这篇关于如何在Linux上使用grep仅显示文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文