grep 的用法

来源:互联网 发布:淘宝网购 编辑:程序博客网 时间:2024/04/30 09:13

[root @test /root ]# grep [-acinv] '搜寻字符串' filename
参数说明:
-c 只输出匹配行的计数。
-i 不区分大小写(只适用于单字符)。
-h 查询多文件时不显示文件名。
-l 查询多文件时只输出包含匹配字符的文件名。
-n 显示匹配行及行号。
-s 不显示不存在或无匹配文本的错误信息。
-v 显示不包含匹配文本的所有行。

 

[root @test /root]# grep 'root' /var/log/secure 
将 /var/log/secure 这个档案中有 root 的那一行秀出来
[root @test /root]# grep -v 'root' /var/log/secure
若该行没有 root 才将数据秀出来到屏幕上!

[root @test /root]# last | grep root
若该行有 root 才将数据秀出来到屏幕上!

[root @test /root]# grep [A-Z]ANPATH /etc/man.config
将 /etc/man.config 这个档案当中,所有有:
[任何一个大写字符]后面接 ANPATH 的那一行就显示出来!
例如 AANPATH, BANPATH.... ZANPATH 等等!

原创粉丝点击