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
下一篇 2018-03-31

相关推荐

  • 第十周作业

    1、Centos7系统下实现httpd-2.2的安装,并分别实现prefork、worker、event等几种工作方式
    2、简述request报文请求方法和状态响应码
    3、详细描述httpd虚拟主机、站点访问控制、基于用户的访问控制、持久链接等应用配置实例

    Linux笔记 2018-07-14
  • Linux上的文件管理类命令

    一、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。(1)目录管理命令——ls:列出指定目录下的内容格式:ls [OPTION]… [FILE]…-a:显示所有文件包括隐藏文件-A:显示除.和..之外的所有文件-l,–long:显示文件的详细属性信息-h:对文件大小进行单位换算,可能影响精度-d:查…

    Linux笔记 2018-05-19
  • linux网络相关

    网络配置 重启失效 ifconfig 网络地址显示,地址配置 ifconfig 接口 IP/netmask [up|down] [-|+]promisc up 打开 down 关闭 -promisc关闭混杂模式 +promisc打开混杂模式,混杂模式用来监听网络数据 ifconfig eth0:1 ip/netmask route 路由管理命令 查看路由 -…

    Linux笔记 2018-05-06
  • linux基础3

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who | cut -d ‘ ‘ -f1 | sort -u root 2、取出最后登录到当前系统的用户的相关信息。 [root@localhost ~]# last -1 | id uid=0(root…

    Linux笔记 2018-07-08
  • 用户。组 ,文件的权限管理

    tr .grep 命令

    2018-04-02
  • 用户管理类命令

    1.列出当前系统上所有已经登录的用户的用户名,注意,同一个用户登录多次则只显示一次 [root@localhost tmp]# who |cut -d” ” -f1 |sort -u root test zach 2.取出最后登录到当前系统的用户的相关信息 [root@localhost tmp]# grep $(w|tail -n 1 |awk -F ” …

    Linux笔记 2018-05-27

评论列表(1条)

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

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