您想要的命令名为 tee
:
foo | tee output.file
例如,如果您只关心标准输出:
ls -a | tee output.file
如果要包括stderr,请执行以下操作:
program [arguments...] 2>&1 | tee outfile
2>&1将通道2(stderr /标准错误)重定向到通道1(stdout
/标准输出),以便将两者都写为stdout。该
tee命令还将其定向到给定的输出文件。
此外,如果要 附加 到日志文件,请
tee -a用作:
program [arguments...] 2>&1 | tee -a outfile



