重定向管道

34 篇文章 0 订阅

输出重定向:

“>”

[root@localhost ~]# head -2 /etc/passwd > 1.txt 
[root@localhost ~]# cat 1.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin

输出重定向追加:
“>”

[root@localhost ~]# date  >> 1.txt 
[root@localhost ~]# cat 1.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
2020年 07月 30日 星期四 19:19:48 CST

2>>追加到错误的消息
&>>追加全部的消息
输入重定向:

[root@localhost ~]# mail -s“111” zz    < 1.txt   (发送标题为111的邮件给zz 内容为上文的1.txt  )

管道:

|
前者的输出作为后者的输入

[root@localhost ~]#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管道
三通管道,即交给另一个程序处理,又保存一份副本

[root@localhost ~]#cat /etc/passwd | tee 1.txt | 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

传递参数Xargs

cp rm一些特殊命令就是不服其他程序。先准备几个文本

[root@localhost ~]# touch /home/touch{1..5}      
[root@localhost ~]# ls /home/
touch1  touch2  touch3  touch4  touch5

若收到消息需要删除某几个文件

[root@localhost ~]# vim rm.txt
/home/touch1
/home/touch3
/home/touch5
[root@localhost ~]# cat rm.txt | rm -rvf
已删除"/home/touch1"
已删除"/home/touch3"
已删除"/home/touch5"
[root@localhost ~]# ls /home
touch2  touch4
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C语言标准库中有一个函数叫做freopen(),它可以用于重定向C程序的输入和输出流。通过调用freopen()函数,我们可以将标准输入流stdin和标准输出流stdout重定向到文件或者管道中。 要将C程序的标准输入流重定向管道,可以使用如下命令: ``` freopen("input.txt", "r", stdin); ``` 这会将程序的标准输入流重定向到名为"input.txt"的文件中。这样,程序执行时会将文件中的内容作为输入。 同样地,要将C程序的标准输出流重定向管道,可以使用如下命令: ``` freopen("output.txt", "w", stdout); ``` 这会将程序的标准输出流重定向到名为"output.txt"的文件中。这样,程序执行后的输出会被写入到文件中。 需要注意的是,freopen()函数也可以对C中的cin和cout进行重定向。使用方法与上述类似,只需要将文件名替换为管道的名称即可。 通过这种方式,我们可以在C程序中实现输入输出的重定向,从而实现输入和输出的管道操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [C++输入输出重定向(3种方法)](https://blog.csdn.net/weixin_39536630/article/details/116964030)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值