How to redirect both stdout and stderr to a file

This question already has an answer here:

  • How can I redirect and append both stdout and stderr to a file with Bash? 6 answers

  • If you want to log to the same file:

    command1 >> log_file 2>&1
    

    If you want different files:

    command1 >> log_file 2>> err_file
    

    The simplest syntax to redirect both is:

    command &> logfile
    

    If you want to append to the file instead of overwrite:

    command &>> logfile
    

    你可以这样做2>&1:

     command > file 2>&1
    
    链接地址: http://www.djcxy.com/p/77102.html

    上一篇: 仅在“调试”模式下管理bash stdout

    下一篇: 如何将stdout和stderr重定向到文件