The command you want is named tee
:
(您想要的命令名为tee
:)
foo | tee output.file
For example, if you only care about stdout:
(例如,如果您只关心标准输出:)
ls -a | tee output.file
If you want to include stderr, do:
(如果要包括stderr,请执行以下操作:)
program [arguments...] 2>&1 | tee outfile
2>&1
redirects channel 2 (stderr/standard error) into channel 1 (stdout/standard output), such that both is written as stdout.
(2>&1
将通道2(stderr /标准错误)重定向到通道1(stdout /标准输出),以便将两者都写为stdout。)
It is also directed to the given output file as of the tee
command. (从tee
命令开始,它也被定向到给定的输出文件。)
Furthermore, if you want to append to the log file, use tee -a
as:
(此外,如果要追加到日志文件,请使用tee -a
作为:)
program [arguments...] 2>&1 | tee -a outfile
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…