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

相关推荐

  • 在CentOS7上编译安装apache 2.4源码包,并启动此服务

    1 关闭firwalld systemctl stop firewalld systemctl disable firewalld 2 关闭SElinux setenforce 0 vim /etc/selinux/config 找到以SELINUX开头的那行,修改成SELINUX=disabled 以下就是脚本里的内容,执行就OK了 yum groupin…

    Linux笔记 2018-04-22
  • 第七周

    1、简述linux操作系统启动流程 inux系统启动流程大致是这样的: post ->BIOS(Boot Sequence) –> MBR(GRUB) –> Kernel(ramdisk) –> rootfs –> /sbin/init(/etc/inittab) BIOS 主板在接通电源后,BIOS会第一个获得系统的控制权。B…

    Linux笔记 2018-07-15
  • N31第四周

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 cp /etc/skel  /home/tuser1 -r chmod  -R go=   /home/tuser1 2、编辑/etc/group文件,添加组hadoop。 echo hadoop:x:2018 >&g…

    Linux笔记 2018-07-16
  • 小白加薪升职记之正则表达式基础

    正则表达式基础命令

    Linux笔记 2018-06-01
  • Linux学习笔记——权限管理

    Linux学习笔记——权限管理 前言: Linux下的权限管理与日常使用的windows有众多与众不同之处。这些特性使得Linux在实际生产作业中更加安全与高效,发挥着各种灵活的作用。本文简要写下笔者对Linux权限管理的理解,供参考与复习,欢迎指正。 回顾: 确认文件的权限与所有者: 使用ll(即ls -l) 命令可查看这个文件的详细信息。 $ ll da…

    2018-04-07

评论列表(1条)

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

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