如何在管道命令中保存终端屏幕输出



我有几个命令正在管道。第一个命令给出一个大文件输出,而它在屏幕上的输出只是一个非常简短的统计摘要。大文件输出通过管道处理得很好,但我想将屏幕输出保存到文本文件中,所以我的问题是如何在管道内做到这一点?

到目前为止,我已经尝试使用以下tee

&> someFile.txt
> someFile.txt
>> someFile.txt

但是他们都给了我大文件输出,但我只想要屏幕短输出。有什么想法吗?

如果您只想在 stdout 上和当前目录中名为 log 的文件中输出command_to_refine_big_output,则可以:

command_with_big_output | command_to_refine_big_output | tee log

请注意,这只会将标准输出写入日志文件,如果您希望标准输出,您可以执行以下操作:

command_with_big_output | command_to_refine_big_output 2>&1 | tee log

或者,如果你想要所有输出,错误包括整个链:

command_with_big_output 2>&1 | command_to_refine_big_output 2>&1 | tee log

最新更新