输出重定向:
“>”
[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