Questions
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 {} ;
How can I just get the file-names (with paths) but without the matches? Do I have to use xargs? Didn t see a way to do this on my grep man page.
Answers
The standard option grep -l (that is a lowercase L) could do this.
http://pubs.opengroup.org/onlinepubs/007908799/xcu/grep.html
http://pubs.opengroup.org/onlinepubs/007908799/xcu/grep.html
-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.
Source
License : cc by-sa 3.0
http://stackoverflow.com/questions/6637882/how-can-i-use-grep-to-show-just-filenames-no-in-line-matches-on-linux
Related