同时在屏幕和文件上显示标准输出

b.b*_*.b. 5 unix bash shell scripting stdout

我想将标准输出从我的脚本记录到文件中,但也可以在屏幕上显示它以进行实时监控.该脚本每秒输出大约10次.

我试图将stdout重定向到一个文件,然后从另一个终端尾部-f该文件,但由于某种原因,tail更新屏幕的速度明显慢于脚本写入文件.

造成这种滞后的原因是什么?是否有另一种方法可以在我的终端和文件中获取一个标准输出流以供以后检查?

fab*_*fab 8

我不能说为什么tail滞后,但你可以使用tee:

Redirect output to multiple files, copies standard input to standard output and also to any files given as arguments. This is useful when you want not only to send some data down a pipe, but also to save a copy.

例: <command> | tee <outputFile>