管道命令 linux,linux下的管道命令 ‘|’

管道命令操作符是:”|”,它仅能处理经由前面一个指令传出的正确输出信息,也就是 standard output 的信息,对于 stdandard

error 信息没有直接处理能力。然后,传递给下一个命令,作为标准的输入 standard input.

使用说明

command1正确输出,作为command2的输入 然后comand2的输出作为,comand3的输入 ,comand3输出就会直接显示在屏幕上面了。

通过管道之后:comand1,comand2的正确输出不显示在屏幕上面

注意:

1、管道命令只处理前一个命令正确输出,不处理错误输出

2、管道命令右边命令,必须能够接收标准输入流命令才行。

[chengmo@centos5 shell]$ cat test.sh | grep -n 'echo'

5: echo "very good!";

7: echo "good!";

9: echo "pass!";

11: echo "no pass!";

#读出test.sh文件内容,通过管道转发给grep 作为输入内容

[chengmo@centos5 shell]$ cat test.sh test1.sh | grep -n 'echo'

cat: test1.sh: 没有那个文件或目录

5: echo "very good!";

7: echo "good!";

9: echo "pass!";

11: echo "no pass!";

#cat test1.sh不存在,错误输出打印到屏幕,正确输出通过管道发送给grep

[chengmo@centos5 shell]$ cat test.sh test1.sh 2>/dev/null | grep -n 'echo'

5: echo "very good!";

7: echo "good!";

9: echo "pass!";

11: echo "no pass!";

#将test1.sh 没有找到错误输出重定向输出给/dev/null 文件,正确输出通过管道发送给grep

[chengmo@centos5 shell]$ cat test.sh | ls

catfile httprequest.txt secure test testfdread.sh testpipe.sh testsh.sh testwhile2.sh

envcron.txt python sh testcase.sh testfor2.sh testselect.sh test.txt text.txt

env.txt release sms testcronenv.sh testfor.sh test.sh testwhile1.sh

#读取test.sh内容,通过管道发送给ls命令,由于ls 不支持标准输入,因此数据被丢弃

作用接收标准输入的命令才可以用作管道右边。否则传递过程中数据会抛弃。 常用来作为接收数据管道命令有:sed,awk,cut,head,top,less,more,wc,join,sort,split 等等,都是些文本处理命令。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值