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运维部落立场,如若转载,请注明出处:https://www.178linux.com/94068

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

相关推荐

  • 初学Linux之标准I/O和管道

    标准输入和输出 程序是由指令+数据组成程序的数据流有三种: 输入数据流:<–标准输入(stdin),一般默认是键盘输出数据流:–>标准输出(stdout),一般默认到终端窗口错误输出流:–>标准错误(stderr),一般默认到终端窗口 标准输入:0标准输出:1错误输出:2 I/O重定向:改变默认位置 输出…

    Linux笔记 2018-04-03
  • 第二周作业

    第二周

    Linux笔记 2018-05-20
  • 无题()

    周志

    Linux笔记 2018-06-01
  • shell脚本进阶—课堂总结

    循环、函数、会持续更新

    Linux笔记 2018-05-10
  • linux基础

    计算机的组成及其功能 计算机初始设计出的时候,就遵循冯诺依曼体系,主要有四部分组成,cpu(中央处理器;运算器和控制器),存储器,输入设备和输出设备 cpu: 运算器、控制器、寄存器,缓存(为了提高cpu性能的加速部件) 存储器:内存,RAM(随机访问存储器) 输入:对计算机下指令,提供让机器操作的数据等;不如键盘,鼠标 输出:输出数据加工后的结果;比如显示…

    Linux笔记 2018-06-24
  • RIAD及逻辑卷理论

    该篇内容纯理论知识,部分内容引起不适,望谅解

    Linux笔记 2018-04-29

评论列表(1条)

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

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