|-- grep
|-- 过滤含有‘root’字符的行
[root@wan ~]# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
|-- 忽略大小写,匹配含有‘root’字符的行
[root@wan ~]# grep -i root passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
ftp:x:14:50:FTP User:/varRooT/ftp:/sbin/nologin
nobody:ROOTx:65534:65534:Kernel Overflow User:/:/sbin/nologin
polkitd:x:998:rooT996:User for polkitd:/:/sbin/nologin
geoclue:x:995:992:ROOtUser for geoclue:/var/lib/geoclue:/sbin/nologin
|--过滤含有‘root’字符的行数
[root@wan ~]# grep root -c /etc/passwd
2
|-- 过滤以‘root’开头的行
[root@wan ~]# grep ^root /etc/passwd
root:x:0:0:root:/root:/bin/bash
|-- 过滤以‘bash’结尾的行
[root@wan ~]# grep bash$ /etc/passwd
root:x:0:0:root:/root:/bin/bash
pcpqa:x:974:974:PCP Quality Assurance:/var/lib/pcp/testsuite:/bin/bash
student:x:1000:1000:student:/home/student:/bin/bash
|-- 匹配不是以nologin结尾的行
[root@wan ~]# grep -v nologin passwd
root:x:0:0:root:/root:/bin/bash
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
pcpqa:x:974:974:PCP Quality Assurance:/var/lib/pcp/testsuite:/bin/bash
student:x:1000:1000:student:/home/student:/bin/bash
SHELL 之 文本三剑客 -- grep
最新推荐文章于 2023-01-07 18:16:42 发布