2011-08-04 43 views
5
根据手册的grep

grep的-l和grep -ln

-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,当发现匹配时,这似乎在精,含有该匹配的文件名是呼应。

但是,当我做grep -ln,grep回声事件的每一行。

确定grep -l确实意味着停止发现匹配的第一个匹配并停止扫描,而grep -ln会忽略-l标志?

回答

6

这些选项不兼容。如果要显示每个文件中第一个匹配的行号(仅限第一个匹配项),请使用grep -Hnm 1

-H,--with文件名
打印的文件名的每场比赛。

-n,--line数
前缀与它的输入文件中的行号输出的每一行。

-m NUM,--max计数= NUM
停止后NUM匹配线读出的文件。