在终端上打印并同时打印到文件中?

Xan*_*der 3 linux shell terminal

我有一个shell脚本来压缩一些数据..我想将结果打印到一个文件中,但这样做会阻止结果显示在终端上.有没有一种方法可以在屏幕上打印结果并写入文件.提前致谢.

Sha*_*hin 12

将输出传递给tee命令.

例:

[me@home]$ echo hello | tee out.txt
hello
[me@home]$ cat out.txt 
hello
Run Code Online (Sandbox Code Playgroud)

请注意,stdout echo打印出来并写入thr tee命令指定的文件.


J00*_*0MZ 5

请注意,您可以添加-a标志tee以附加到输出文件

[me@home]$ echo hello | tee out.txt
hello
[me@home]$ echo hello again | tee -a out.txt
hello again
[me@home]$ cat out.txt
hello
hello again
Run Code Online (Sandbox Code Playgroud)