重定向管道

34 篇文章 0 订阅

输出重定向:

“>”

[root@localhost ~]# head -2 /etc/passwd > 1.txt 
[root@localhost ~]# cat 1.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin

输出重定向追加:
“>”

[root@localhost ~]# date  >> 1.txt 
[root@localhost ~]# cat 1.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
2020年 07月 30日 星期四 19:19:48 CST

2>>追加到错误的消息
&>>追加全部的消息
输入重定向:

[root@localhost ~]# mail -s“111” zz    < 1.txt   (发送标题为111的邮件给zz 内容为上文的1.txt  )

管道:

|
前者的输出作为后者的输入

[root@localhost ~]#cat /etc/passwd | head -3
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin

tee管道
三通管道,即交给另一个程序处理,又保存一份副本

[root@localhost ~]#cat /etc/passwd | tee 1.txt | head -3
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin

传递参数Xargs

cp rm一些特殊命令就是不服其他程序。先准备几个文本

[root@localhost ~]# touch /home/touch{1..5}      
[root@localhost ~]# ls /home/
touch1  touch2  touch3  touch4  touch5

若收到消息需要删除某几个文件

[root@localhost ~]# vim rm.txt
/home/touch1
/home/touch3
/home/touch5
[root@localhost ~]# cat rm.txt | rm -rvf
已删除"/home/touch1"
已删除"/home/touch3"
已删除"/home/touch5"
[root@localhost ~]# ls /home
touch2  touch4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值