加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

unix – grep -l和grep -ln

发布时间:2020-12-15 21:45:15 所属栏目:安全 来源:网络整理
导读:根据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,这似乎很好,因为当找到匹配时,回显
根据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,这似乎很好,因为当找到匹配时,回显包含匹配的文件名.

但是,当我执行grep -ln时,grep会回显该事件的每一行.

grep -l是否真的意味着在找到第一次匹配时停止并停止扫描,而grep -ln将忽略-l标志?

解决方法

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

-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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读