重定向管道

1.重定向:
标准输入,标准输出,标准错误FD简介file descriptors,FD,文件描述符,进程使用文件描述符来管理文件
图示:在这里插入图片描述
0:是键盘只读
1,2是终端可以理解为屏幕
3+是问文件可读可写
2.输出重定向
正确输出:1>等价于>
1>> 等价于>>
错误输出:
2> 没有简写
2>> 没有简写
3管道:
进程管简介:管道命令可以将多条命令组合起来,一次性完成复杂的处理任务。
语法:command1 | command2 |command3 |…
案例:[root@qianfeng ~]# cat /etc/passwd | tail -3
[root@qianfeng ~]# ps aux | grep ‘sshd’

4.tee管道:三通管道,即交给另一个程序来处理,又保存一份副本
案例:[root@localhost ~]# cat /etc/passwd |tee 88.txt | tail -1
qianfeng❌1001:1001::/home/qianfeng:/bin/bash
[root@localhost ~]# cat 888.txt
888.txt文本中是什么内容呢?一行还是所有行?
所有行,因为是命令1 (cat)处理的结果
5.参数传递Xargs
cp rm一些特殊命令就是不服其他程序。
环境准备:[root@localhost ~]# touch /home/file{1…5}
[root@localhost ~]#ls /home
接到消息,部分文件需要删除:
[root@localhost ~]# vim files.txt
/home/file1
/home/file3
/home/file5
使用管道:
[root@localhost ~]# cat files.txt |rm -rvf 失败
之前的不行,下面加xargs
[root@localhost ~]# cat files.txt |xargs rm -rvf
removed ‘/home/file1’
removed ‘/home/file3’
removed ‘/home/file5’
[root@localhost ~]#ls /home
通过|xargs成功连接rm命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值