如何将 stdout 和 stderr 都重定向到文件

如何将 stdout 和 stderr 都重定向到文件

问题描述:

我正在运行一个 bash 脚本,它为命令的执行创建一个日志文件

I am running a bash script that creates a log file for the execution of the command

我使用以下内容

Command1 >> log_file
Command2 >> log_file

这只会发送标准输出,而不是终端上出现的标准错误.

This only sends the standard output and not the standard error which appears on the terminal.

我可以将 stderr 和 stdout 都记录到一个文件中吗?

Can I log both the stderr and stdout logged to a file?

如果你想登录到同一个文件:

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