Redirect stderr and stdout in Bash

后端 未结 15 922
日久生厌
日久生厌 2020-11-22 08:18

I want to redirect both stdout and stderr of a process to a single file. How do I do that in Bash?

15条回答
  •  日久生厌
    2020-11-22 08:48

    You can redirect stderr to stdout and the stdout into a file:

    some_command >file.log 2>&1 
    

    See http://tldp.org/LDP/abs/html/io-redirection.html

    This format is preferred than the most popular &> format that only work in bash. In Bourne shell it could be interpreted as running the command in background. Also the format is more readable 2 (is STDERR) redirected to 1 (STDOUT).

    EDIT: changed the order as pointed out in the comments

提交回复
热议问题