grep命令与管道命令实战讲解

grep

主要参数:

-v 取反

-i 忽略大小写

^# 以井号键开头

^$ 空行

-n 对过滤的内容加上行号

实战演练:

[root@localhost ~]# grep "nologin|root" /etc/passwd|wc -l
0
[root@localhost ~]# grep "nologin\|root" /etc/passwd|wc -l   #\转义字符生效
37
[root@localhost ~]# egrep "nologin|root" /etc/passwd |wc -l
37
[root@localhost ~]# 

管道

管道命令是从左到右顺序执行前边的执行报错不再执行后续内容

演示:

[root@localhost ~]# ps -aux |grep "sshd"			#过滤sshd相关进程
root       1097  0.0  0.0 105996   220 ?        Ss   08:19   0:00 /usr/sbin/sshd -D
root       3381  0.0  0.0 112680   992 pts/0    S+   08:41   0:00 grep --color=auto sshd
[root@localhost ~]# ps -aux |grep "sshd"|cat -n			#过滤后加上序号
     1	root       1097  0.0  0.0 105996   220 ?        Ss   08:19   0:00 /usr/sbin/sshd -D
     2	root       3407  0.0  0.0 112680   988 pts/0    S+   08:41   0:00 grep --color=auto sshd
[root@localhost ~]# ps -aux |grep "sshd"|grep -v grep |cat -n		#排除掉grep命令进程本身
     1	root       1097  0.0  0.0 105996   220 ?        Ss   08:19   0:00 /usr/sbin/sshd -D
[root@localhost ~]# ifconfig |grep inet |head -1|awk '{print $2}' #获取IP地址
192.168.199.129

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

醉里看星辰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值