-c 行数 -i 不区分大小写 -n 显示行号 -v 取反,将除了其意外的过滤并显示出来 -r 遍历全部子目录 -A 后面跟数字,过滤出符合要求的行以及下面n行 -B 同上,过滤出符合要求的行以及上面n行 -C 同上,同时过滤出符合要求的行以及上下各n行php
特殊符号**^**:放在括号里面是取反,外面是以什么开头
例如 [^0-9] 那就是非数字(包括字母+特殊符号);
例如[^a-zA-Z] 那就是非字母(包括数字+特殊符号)
例如[^0-9a-zA-Z]那就是非数字字母(特殊符号)centos
grep -n 'root' /etc/passwd grep -nv 'nologin' /etc/passwd grep '[0-9]'/etc/inittab grep -v '[0-9]'/etc/inittab grep -v '^#' /etc/inittab grep -v '^#' /etc/inittab|grep -v '^$' grep '^[^a-zA-Z]' test.txt grep 'r.o' test.txt //.表示匹配任意字符 grep 'oo*' test.txt //*表示匹配其左边0到n个重复的字符 grep '.*' test.txt //.*表示匹配全部字符,包括空行 grep 'o\{2\}' /etc/passwd //{}表示其前面字符的一个范围
[root@centos001 grep]# grep '[0-9]' passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin [root@centos001 grep]# grep -v '[0-9]' passwd [root@centos001 grep]#
[root@centos001 grep]# grep -n '^#' inittab //查看带有#的 1:# inittab is no longer used when using systemd. [root@centos001 grep]# grep -nv '^#' inittab //查看没有#号的 9:kJAHkladh
[root@centos001 grep]# grep '[^0-9]' inittab //过滤并列出除了数字的字符 # inittab is no longer used when using systemd. [root@centos001 grep]# grep '^[^0-9]' inittab //过滤并列出除了数字开头的字符 # inittab is no longer used when using systemd. [root@centos001 grep]# grep -nv '^[^0-9]' inittab //过滤并列出与上面相反的内容 8:123123421
[root@centos001 grep]# grep 'r.o' passwd //这个点表明任意字符 root:x:0:0:root:/root:/bin/bash [root@centos001 grep]# grep 'aming.*bash' passwd //在。*首位输入字符串的首尾名称 aming:x:1001:1007::/home/aming:/bin/bash
grep 'o\{2\}' /etc/passwd //指定要过滤字符的出现字数 注:这个必须加上转义字符\ egrep 'o{2}' /etc/passwd //egrep可不用加\ egrep 'o+' /etc/passwd //过滤一个或多个指定的字符,匹配一个或多个+号前面的字符 egrep 'oo?' /etc/passwd //过滤0个或一个指定字符,?前的字符为0或1 egrep 'root|nologin' /etc/passwd //竖线表示或者的意思 egrep '(oo){2}' /etc/passwd
[root@centos001 grep]# grep 'o+a' passwd //这里能看到grep是不能和+号一块儿使用的 [root@centos001 grep]# egrep 'o+m' passwd // 指定过滤 user1:x:1000:1000::/home/user1:/bin/bash
grep -r --include="*.php" 'eval' /data/