• 关于shell中的commond >out.file 2>&1 命令


    shell命令:ls  -al  >out.log  2>&1  

    命令含义:将shell命令的1(stdout)输出 和 2(stderr)输出都重定向到out.log这个文件中 。

    解释:ls  -al   ,一个commond执行后会有2种输出:1(stdout)输出 和 2(stderr) ,默认是将1重定向到标准的输出屏幕上 。

             ls  -al  >out.log ,是将默认的输出(其实就是输出到屏幕上的stdout)重定向out.log文件中 。

             2>&1  重定向的意思,&1表示获得1(stout)的标准输出,既是将2重定向到1 ,因为现在的1已经被重定向到了屏幕(屏幕又被重定向到了out.log文件中),所以stdout和stderr就被重定向到了out.log文件中  。

            其他几种写法的含义:

            ls  -al  >out.log  2>1   :默认的1(stdout)重定向到  out.log中,2(stderr)被重定向到文件1中 。

           ls 2>1测试一下,不会报没有2文件的错误,但会输出一个空的文件1;
           ls xxx 2>1测试,没有xxx这个文件的错误输出到了1中;
           ls xxx 2>&1测试,不会生成1这个文件了,不过错误跑到标准输出了;
           ls xxx >out.txt 2>&1, 实际上可换成 ls xxx 1>out.txt 2>&1;重定向符号>默认是1,错误和输出都传到out.txt了。

  • 相关阅读:
    线性代数思维导图——3.向量
    微分中值定理的基础题型总结
    构造函数
    Python课程笔记(七)
    0241. Different Ways to Add Parentheses (M)
    0014. Longest Common Prefix (E)
    0013. Roman to Integer (E)
    0011. Container With Most Water (M)
    0010. Regular Expression Matching (H)
    0012. Integer to Roman (M)
  • 原文地址:https://www.cnblogs.com/serendipity/p/2409343.html
Copyright © 2020-2023  润新知