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

相关推荐

  • Linux系统目录简介

    帮助理解linux系统目录结构和作用

    2018-04-15
  • shell 编程基础

    命令错误 后面的命令继续执行 语法错误 后面的命令不执行 bash -n 检查语法错位 bash -x 查看脚本的执行过程 【排错】 ++文件属性上的 显示是嵌套命令 变量 引用变量要加$符号 echo 是显示字符串的 如果命令能识别变量 可以不加$ 识别不了就压加$ 变量尽量用“ ”引起来 保留里面的格式 name =`whoami` echo &#822…

    Linux笔记 2018-04-15
  • ansible_playbook

    —– hosts: allremote_user: root vars:ports:-81-82-83 vars:ports:– listen_port: 81– listen_port: 82– listen_port: 83 vars:ports:– web1:port: 81#na…

    Linux笔记 2018-07-30
  • 脚本基础课后练习

    (1)编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小 #!/bin/bash echo “MY hostname is `hostname`”echo “My IPv4 address is `ifconfig …

    Linux笔记 2018-04-13
  • vim编辑器

    文本编辑器种类: 行编辑器:sed 全屏编辑器:nano,vi vim编辑器 vi文本编辑器 +#打开文件后让光标处于第#行 +/ PATTERN :打开文件后,直接让光标处于第一个被 PATTERN 匹配到的行的 行首 –b file 二进制方式打开文件 –d file1 file2… 比较多个文件 -m file 只读打开文件 三种模式: 命令h,j,k…

    2018-04-06
  • yum 常见问题

    yum 常见问题

    Linux笔记 2018-06-06

评论列表(1条)

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

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