Liunx管道和重定向

本文介绍了Linux系统中的重定向和管道操作。重定向包括使用">"进行覆盖写入和">>"进行追加写入,以及输入重定向"<"。管道部分讲解了如何通过管道连接命令,特别提到了`tee`命令用于同时输出到屏幕和文件,以及`xargs`用于将标准输入转换为命令参数。最后,文章总结了这些概念在实际应用如Apache、Nginx、Docker等云集群环境中的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、重定向

FD:相当于快捷方式,超链接

 ">"  :  //相当于调用FD   向后面文件输入信息;

">>" 追加输入

输入重定向 <

二、 管道

 

 

eg:

[root@localhost alice]# 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管道

eg:

[root@localhost alice]# cat /etc/passwd |tee file88.txt | head -1
root:x:0:0:root:/root:/bin/bash

//输出文件  /etc/passwd 到file88.txt  并保存后 输出一行到显示器
[root@localhost alice]# cat /etc/passwd |grep "root" | head -1
root:x:0:0:root:/root:/bin/bash

[root@localhost alice]# cat /etc/passwd |grep "root"
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

[root@localhost alice]# cat /etc/passwd |grep "root" | head -1
root:x:0:0:root:/root:/bin/bash

[root@localhost alice]# cat /etc/passwd |grep "root" |tee file9.txt|  head -1
root:x:0:0:root:/root:/bin/bash

参数传递Xargs

 

[root@localhost alice]# touch /home/file{1..5}  //创建文件  1 2 3 4 5
[root@localhost alice]# ls /home/
alice  file2  file4  jack     test.txt  user    user02  volf
file1  file3  file5  nuinui1  u1        user01  user1   xulei

[root@localhost alice]# vim file1.txt     //file1.txt 是文件  
[root@localhost alice]# cat file1.txt
/home/file2
/home/fiel3
/home/file5       //内容


[root@localhost alice]# cat file1.txt | rm -rvf
cat: file1.txt: 没有那个文件或目录                        //不能删除


[root@localhost alice]# cat file1.txt | xargs rm -rvf       //加入xargs管道删除这些2  3  5文件
已删除"/home/file2"
已删除"/home/file5"

[root@localhost alice]# [root@localhost alice]# ls /home
alice  file3  jack     test.txt  user    user02  volf
file1  file4  nuinui1  u1        user01  user1   xulei

 总结                |  tee    xarg s

 

后面   阿帕奇   Ngx   刀客特         云          集群   拍森

                 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值