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
, this seems fine in that when a match is found, the file na开发者_JS百科me containing the match is echoed.
However when i do a grep -ln
, grep echoes every line of the occurrence.
Does grep -l
really mean to stop when the first occurrence of the match is found and stop scanning, while grep -ln
will ignore the -l
flag?
Those options are incompatible. Use grep -Hnm 1
if you want to display the line number of the first match (and only the first match) in each file.
-H, --with-filename
Print the filename for each match.-n, --line-number
Prefix each line of output with the line number within its input file.-m NUM, --max-count=NUM
Stop reading a file after NUM matching lines.
精彩评论