grep -l和grep -ln

Oh *_*oon 5 unix grep

根据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.
Run Code Online (Sandbox Code Playgroud)

grep -l,这似乎很好,因为当找到匹配时,回显包含匹配的文件名.

但是,当我这样做时grep -ln,grep会回应每一行.

难道grep -l真的是在本场比赛的第一次出现被发现停止和停止扫描,同时grep -ln将忽略-l标志?

Joh*_*ica 7

这些选项不兼容.使用grep -Hnm 1,如果你要显示的第一场比赛的每个文件中的行号(只有第一场比赛).

-H, - with-filename
打印每个匹配的文件名.

-n, -
line -number使用输入文件中的行号为每行输出添加前缀.

-m NUM, - max-count = NUM
NUM个匹配行后停止读取文件.