Grep -l and grep -ln

according to the manual for grep,

-l, --files-with-matches
          Suppress normal output; instead print the  name  of  each  input
          file  from  which  output would normally have been printed.  The
          scanning will stop on the first match.

grep -l, it seems wonderful in that when a match is found, the name of the file containing the match is reflected.

However, when I do a grep -ln, grep echoes each entry line.

Does it really grep -lstop when it detects the first match and stops scanning, but grep -lnignores the flag -l?

+5
source share
1 answer

These options are incompatible. Use grep -Hnm 1if you want to display the line number of the first match (and only the first match) in each file.

-H, --with-filename
Print the file name for each match.

-n, -line-number
.

-m NUM, -max-count = NUM ​​
NUM .

+6

All Articles