Unix grep-l和grep-ln
根据grep的手册Unix grep-l和grep-ln,unix,grep,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. grep-l,这似乎很好,因为
-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
标志?这些选项不兼容。如果要在每个文件中显示第一个匹配(并且仅显示第一个匹配)的行号,请使用grep-Hnm 1
-H,--带文件名
打印每个匹配的文件名
-n,--行号在输出的每一行前加上输入文件中的行号 -m NUM,--max count=NUM
在NUM匹配行之后停止读取文件