一、什么是管道
管道命令可以将多条命令组合起来,一次性完成复制的处理任务
1前者的输出是2后者的输入,2前者的输出是3后者的输入.
1、tee管道
取出第3个管道出的输出文档。
| | | | |
例1:tee输出内容的数量为多个
[root@localhost ~]# cat /etc/passwd | tail -1
user02:x:1203:1203::/home/user02:/sbin/nologin
[root@localhost ~]# cat /etc/passwd | tee /home/CloudDB/file11.txt | tail -1
user02:x:1203:1203::/home/user02:/sbin/nologin
[root@localhost ~]# cd /home/CloudDB
[root@localhost CloudDB]# head -2 file11.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[root@localhost CloudDB]#
[root@localhost ~]# cat /etc/passwd | tee /home/CloudDB/file11.txt | tail -1
这句指令是将passwd的输出写入到/home/CloudDB/file11.txt中
其中file11.txt中有很多的输出。
例2:tee输出的文件数量为两个
[root@localhost CloudDB]# cat /etc/passwd |grep root |tee /home/CloudDB/file22.txt
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@localhost CloudDB]# cat file22.txt
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@localhost CloudDB]#
查询出相关root的只有两行。
2、特殊的管道 xargs
通过文本来控制文件的删除
[root@localhost CloudDB]# touch file1.txt
[root@localhost CloudDB]# vi file1.txt
[root@localhost CloudDB]# cat file1.txt
/home/CloudDB/file1
/home/CloudDB/file2
/home/CloudDB/file3
[root@localhost CloudDB]# touch file1
[root@localhost CloudDB]# touch file2
[root@localhost CloudDB]# touch file3
[root@localhost CloudDB]# ls
CloudDBstudy file1.txt file2 list1.txt sh.sh taoshukai
file10 file1z~ file3 list.txt tao test.txt
file1
[root@localhost CloudDB]# cat file1.txt |xargs rm -rvf
已删除"/home/CloudDB/file1"
已删除"/home/CloudDB/file2"
已删除"/home/CloudDB/file3"
[root@localhost CloudDB]# ls
CloudDBstudy file1.txt list1.txt sh.sh taoshukai
file10 file1z~ list.txt tao test.txt
[root@localhost CloudDB]#