Linux学习笔记(管道)

这篇博客介绍了Linux中的管道概念,重点讲解了tee管道的使用,包括如何将命令输出同时写入多个文件,并提供了实例。还提及了特殊管道xargs,探讨了其在文本控制文件操作中的应用。
摘要由CSDN通过智能技术生成

一、什么是管道

管道命令可以将多条命令组合起来,一次性完成复制的处理任务

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]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

苏木三少

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

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

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

打赏作者

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

抵扣说明:

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

余额充值