Linux-管道

1、管道

1.1、功能:使用管道控制进程命令输出到其他程序命令

在这里插入图片描述

1.2、管道符号 |
1.3、实例:
        [root@centos6 ~]# ps -ef|grep init
        root          1      0  0 15:53 ?        00:00:01 /sbin/init
        root       2720   2306  0 16:31 pts/0    00:00:00 grep init
   
        ##统计/etc/passwd中用户使用各shell的数量
        [root@centos6 ~]# awk -F: '{print $7}' /etc/passwd|sort|uniq -c
              9 /bin/bash
              1 /bin/sync
              1 /sbin/halt
             26 /sbin/nologin
              1 /sbin/shutdown
        [root@centos6 ~]# ip a|grep inet
            inet 127.0.0.1/8 scope host lo
            inet6 ::1/128 scope host 
            inet 192.168.24.129/24 brd 192.168.24.255 scope global eth1
            inet6 fe80::20c:29ff:fec4:e8ab/64 scope link 
        [root@centos6 ~]# 
        [root@centos6 ~]# 
        [root@centos6 ~]# ip a|grep 'inet '
            inet 127.0.0.1/8 scope host lo
            inet 192.168.24.129/24 brd 192.168.24.255 scope global eth1

2、tee管道

2.1、功能:在不影响其它管道的情况下定向输出结果到文件或终端

在这里插入图片描述

2.2 实例:

        [root@centos6 ~]# df -h|grep '/$'|awk '{print $5}'|awk -F% '{print $1}'
        45
        [root@centos6 ~]# 
        [root@centos6 ~]# df -h|grep '/$'|awk '{print $5}'|tee df.txt|awk -F% '{print $1}'
        45
        [root@centos6 ~]# 
        [root@centos6 ~]# cat df.txt
        45%
        [root@centos6 ~]# 
        [root@centos6 ~]# 
        [root@centos6 ~]# df -h|grep '/$'|tee df.txt |awk '{print $5}'|awk -F% '{print $1}'
        45
        [root@centos6 ~]# cat df.txt
        /dev/sda2       7.6G  3.2G  4.0G  45% /
        [root@centos6 ~]# 
        [root@centos6 ~]# df -h|grep '/$'|tee -a df.txt |awk '{print $5}'|awk -F% '{print $1}'
        45
        [root@centos6 ~]# cat df.txt
        /dev/sda2       7.6G  3.2G  4.0G  45% /
        /dev/sda2       7.6G  3.2G  4.0G  45% /
        [root@centos6 ~]# 
        [root@centos6 ~]# date|tee date.txt
         2019年 09月 24日 星期二 19:46:43 CST
        [root@centos6 ~]# 
        [root@centos6 ~]# cat date.txt
         2019年 09月 24日 星期二 19:46:43 CST

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值