grep 过滤出指定的行
grep ‘root‘ /etc/passwd 过滤root字符的行
grep --color -n ’root‘ /etc/passwd 深色字符显示匹配项
grep --color -nv ’root‘ /etc/passwd 显示没有root字符匹配项
grep --color -n -A 2 'root' 1.txt 匹配并显示下面2行
grep --color -n -B 2 'root' 1.txt 匹配并显示上面2行
grep --color -n -C 2 'root' 1.txt 匹配并显示上下各2行
grep --color -r 'iptables' /etc/* 遍历目录查找有iptables的文件的行
grep --color -rh 'iptables' /etc/* 遍历目录查找有iptables的文件的行(只显示结果,不要文件目录)
gr '[a-zA-Z]' 1.txt 匹配包含字母的行
gr -v '[a-zA-Z]' 1.txt 匹配不包含字母的行gr '^[a-z]' 1.txt 匹配以字母开头的行
gr -v '^[a-z]' 1.txt 匹配不以字母开头的行
gr '^[^0-9]' 1.txt 匹配不以数字开头的行
gr '^$' 1.txt 匹配空行
gr -v '^$' 1.txt 匹配非空行
gr 'r.o' 1.txt 匹配r.o . 可以匹配任意一个字符
gr 'r*o' 1.txt 匹配一个或者多个中间字符
gr 'r.*o' 1.txt 匹配r开头 o 结尾的字符
gr 'r\?o' 1.txt 0或者1个? 前面的字符 故此可以匹配 o 或 ro
egrep --color 'root|nologin' 1.txt 或者匹配项
grep 'root' 1.txt |grep 'nologin' 匹配并且项
egrep --color '(rr)+' 1.txt 匹配整体 rr无限次数
egrep --color '(rr){1,3}' 1.txt 匹配1-3次rr的行
egrep --color '(rr){5}' 1.txt 匹配5次rr的行
egrep --color 'r+o' 1.txt 匹配一个或多个r
\ 脱意字符