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

相关推荐

  • 软硬链接

    软链接和硬链接的区别

    2018-03-31
  • 用PXE批量部署系统

    在部署操作系统的时候可以选择安装centos6还是centos7

    Linux笔记 2018-05-27
  • linux基础知识

    第一周基础知识作业

    2018-05-10
  • N31-3

    基础命令演示

    Linux笔记 2018-07-04
  • MySQL之用户与权限管理

    本节索引: 一、MySQL用户管理 二、MySQL权限管理 三、操作:破解Mysql数据库口令 一、MySQL用户管理 用户账号: MySQL的用户账号由两部分组成:用户名+主机名 ‘USERNAME’@’HOST’ 其中: 主机名HOST可以是IP地址或Network; 如:wxlinux@192.168.3…

    2018-06-09
  • 第十一周作业

    1、搭建php-fpm工作方式的LAMP环境,实现wordpress正常访问 1、 先安装数据库mariadb [root@bogon ~]# yum install mariadb-service 配置数据库主文件 [root@bogon ~]# vim /etc/my.cnf.d/server.cnf 启动数据库 [root@bogon ~]# syst…

    Linux笔记 2018-06-10

评论列表(1条)

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

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