• shell输入输出重定向


    标准输入:0  < , <<或者0< 0<<

    标准输出:1  >,>> 或者1>,1>>

    错误输出:2  2>>,2>

    /dev/null 这个设备,是linux 中黑洞设备,什么信息只要输出给这个设备,都会给吃掉
    将标准输出,错误输出都发送给/dev/null中
    $ ls test.sh test1.sh >/dev/null 2>&1
     
    &,&1代表标准输出
    &2代表错误输出

    //错误输出直接被写在标准输出中,即在终端上屏幕显示。

    :~$ ls -yz 2>&1
    ls: invalid option -- 'y'
    Try 'ls --help' for more information.

    //错误输出会被输出到标准输出,即屏幕显示,而不会写在fname文件中。
    :~$ ls -yz 2>&1 1>fname
    ls: invalid option -- 'y'
    Try 'ls --help' for more information.
    :~$ ls
    AndroidStudioProjects  Desktop    Documents  Downloads  examples.desktop    fname  Music  Pictures    Public    Templates  usr    Videos    work
    :~$ cat fname

    //标准输出会写在fname文件中,错误输出会被输出到标准输出中,即文件fname中。
    :~$ ls -yz 1>fname 2>&1
    :~$ ls
    AndroidStudioProjects  Desktop    Documents  Downloads  examples.desktop    fname  Music  Pictures    Public    Templates  usr    Videos    work
    :~$ cat fname
    ls: invalid option -- 'y'
    Try 'ls --help' for more information.

  • 相关阅读:
    rocketMQ
    RocketMQ 事务消息
    Serial,Parallel,CMS,G1四大GC收集器特点小结
    CMS垃圾收集器与G1收集器
    CMS垃圾回收过程
    MySQL中EXPLAIN解释命令 查看索引是否生效
    redis持久化的几种方式
    深入浅出数据库索引原理
    Java中堆内存和栈内存详解
    jvm垃圾回收机制
  • 原文地址:https://www.cnblogs.com/shamoguzhou/p/6893504.html
Copyright © 2020-2023  润新知