Linux 是否在终端上同时打印并写入文件?

Linux 是否在终端上同时打印并写入文件?,linux,shell,terminal,Linux,Shell,Terminal,我有一个shell脚本,可以greps一些数据。。我想将结果打印到文件中,但这样做会阻止结果显示在终端上。有没有一种方法既可以在屏幕上打印结果,也可以写入文件。 提前谢谢。完全是你的事 将输出通过管道传输到命令 例如: [me@home]$ echo hello | tee out.txt hello [me@home]$ cat out.txt hello 请注意,echo的标准输出和写入thrtee命令指定的文件。注意,您可以将-a标志添加到tee以附加到输出文件 [me@home]$

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

完全是你的事

将输出通过管道传输到命令

例如:

[me@home]$ echo hello | tee out.txt
hello
[me@home]$ cat out.txt 
hello

请注意,
echo
的标准输出和写入thr
tee
命令指定的文件。

注意,您可以将
-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