有没有办法让 Bash 将 STDOUT/STDERR 重定向到一个文件,同时仍然将它们打印到终端?
最佳答案
这会将 STDOUT 和 STDERR 重定向到同一个文件:
some_command 2>&1 | tee file.log
例子
$ touch foo; ls foo asfdsafsadf 2>&1 | tee file.log
ls: asfdsafsadf: No such file or directory
foo
$ cat file.log
ls: asfdsafsadf: No such file or directory
foo
关于linux - 打印 STDOUT/STDERR 并将它们写入 Bash 中的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4739418/