Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

linux - 如何使用grep在Linux上显示文件名?(How can I use grep to show just filenames on Linux?)

How can I use grep to show just file-names (no in-line matches) on Linux?

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

I am usually using something like:

(我通常使用类似的东西:)

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

How can I just get the file-names (with paths), but without the matches?

(我怎样才能获得文件名(带路径),但没有匹配?)

Do I have to use xargs ?

(我必须使用xargs吗?)

I didn't see a way to do this on my grep man page.

(我没有在grep手册页上看到这样做的方法。)

  ask by cwd translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The standard option grep -l (that is a lowercase L) could do this.

(标准选项grep -l (即小写L)可以执行此操作。)

From the Unix standard :

(从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.

You also do not need -H in this case.

(在这种情况下,您也不需要-H 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...