zoukankan      html  css  js  c++  java
  • 关于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了。

  • 相关阅读:
    Flask:flask-script;多app应用;wtforms
    Flask:Locla;偏函数;请求上下文;蓝图;g对象;信号;flask-session
    Flask:闪现; 请求扩展;自定义中间件
    Flask:cookie和session
    Flask:请求与响应
    Flask:重定向;模板语法,
    Flask:路由系统;CBV的代码案例
    软件质量模型
    Selenium with Python 002
    Selenium with Python 001
  • 原文地址:https://www.cnblogs.com/serendipity/p/2409343.html
Copyright © 2011-2022 走看看