Answers:
tee为此目的而存在;它接受一个文件名参数,并将从标准输入读取的数据写入标准输出和文件:
$ prog 2>&1 | tee file
prog |& tee file。
prog |& tee /dev/tty > file可以在管道的中间使用,例如foo |& tee /dev/tty | sed 's/.*\r//' > foo.log,在终端上查看状态行进度更新,但将其从日志文件中过滤掉。或通过让您看到此时的数据,来调试您一起破解的管道。
stdout是文件描述符1,foo > some_file表示打开的只写文件描述符some_file是foo的标准输出。stdout始终转到stdout。