重定向和管道详解


一、重定向(重新定向命令的输出)

1.简介


将前面命令的输出,作为内容,写入到后面的文件
>:覆盖重定向
>>:追加重定向

2.案例

[root@A /]# head -5  /etc/passwd > /opt/p.txt
[root@A /]# cat  /opt/p.txt
 
[root@A /]# hostname
[root@A /]# hostname  >> /opt/p.txt
[root@A /]# cat  /opt/p.txt
 
[root@A /]# echo 123456      
[root@A /]# echo 123456  >  /opt/p.txt
[root@A /]# cat  /opt/p.txt
 
[root@A /]# cat  /etc/hostname
[root@A /]# echo  888888  > /etc/hostname
[root@A /]# cat  /etc/hostname


二、管道(操作符号 | )

1.简介

ls ,rm,mv,cp不支持管道
作用:将前面命令的输出,传递给后面命令,作为后面命令的参数

2.案例


[root@A /]#head  -4  /etc/passwd   |   tail  -1
[root@A /]# head  -8  /etc/passwd  |   tail  -1
[root@A /]# cat -n  /etc/passwd  |  head  -8  |   tail  -1
[root@A /]# ifconfig  |  head  -2
[root@A /]# head  -12  /etc/passwd   |  tail  -5
[root@A /]# head -12 /etc/passwd  |  tail -5  |  cat  -n
[root@A /]# cat -n  /etc/passwd   |  head -12
[root@A /]# cat -n  /etc/passwd   |  head -12  |   tail -5
[root@A /]# cat -n  /etc/passwd  |  head -12  |   tail -5  > /opt/pa.txt
[root@A /]# cat  /opt/pa.txt

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值