cmd > log 2>&1 和 cmd 2>&1 > log的区别

A cmd > log 2>&1
B cmd 2>&1 > log
C cmd &> log
D cmd 2>log >&2
哪个与众不同

Order matters. The way to reason about redirections is to read them from left to right and realize that redirections make streams point at the same place. They don’t make streams point at each other.

What does that mean? If you say 2>&1 then you are redirecting stderr to wherever stdout is currently redirected to. If stdout is going to the console then stderr is, too. If stdout is going to a file then stderr is as well. If you follow this up by then redirecting stdout, stderr still points to what stdout used to point to. It does not “follow” stdout to the new location.

译文:
订单很重要。推理重定向的方法是从左向右读取它们,并意识到重定向使流指向同一个地方。他们不会让流彼此指向。

那是什么意思?如果你这么说,2>&1那么你正在将stderr重定向到stdout当前被重定向到的任何地方。如果标准输出到控制台,那么stderr也是。如果标准输出到一个文件,那么stderr也是。如果您通过重定向标准输出继续执行此操作,stderr仍会指向stdout 用于指向的内容。它不会“跟随”stdout到新的位置。

 

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/94068

(8)
涩葡桃涩葡桃
上一篇 2018-03-31 16:26
下一篇 2018-03-31 19:06

相关推荐

  • RAID

    RAID技术 stripe:条带。将连续的数据切分成相同大小的数据块,把每段数据块分别写入到不同磁盘上的方法。 条带技术可以增加硬盘的读写性能,但是不支持数据容错。最少使用2块盘做条带。磁盘利用率为100% mirror:镜像。镜像技术是将n(2的倍数)块磁盘上的每个数据位同步成相同的数据位。在写数据时,写入2 份数据。镜像技术有容错功能,但是硬盘的写性能有…

    Linux笔记 2018-04-25
  • Linux基础知识点(十二)

    此篇博客只是记录第十四周未掌握或不熟悉的知识点,用来加深印象。

    Linux笔记 2018-06-15
  • DHCP实验

    前期准备 仅主机网段                                 /* 取消dhcp */ /* 虚拟机启动过程中 会卡住一会 找地址 */ yum install dhcp 服务端 网卡配置 静态地址 重启网络 systemctl start dhcpd                /* 报错 没有配置文件 */ 编辑配置文件 sys…

    Linux笔记 2018-05-29
  • yum源搭建

    本地yum源搭建,网络yum源搭建

    Linux笔记 2018-04-21
  • mysql数据库四

    备份和还原 主从复制,

    2018-06-11

评论列表(1条)

  • 涤生
    涤生 2018-04-01 09:09

    补充: cmd 2>&1 >log 错误重定向通过正确重定向直接输出至终端,正确重定向直接输出至log文件
    可以通过 (cmd 2>&1) >log 将错误重定向和正确重定向的内容全部输出至文件