Linux 同时在终端和文件中打印?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10782332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Print on terminal and into file simultaneously?
提问by Xander
I have a shell script that greps some data.. I want to print the result into a file, but doing that prevents the result being displayed on the terminal. Is there a way that can both print the result on the screen and also write into a file. Thanks in advance.
我有一个用于 grep 一些数据的 shell 脚本。我想将结果打印到一个文件中,但这样做会阻止结果显示在终端上。有没有办法既可以在屏幕上打印结果,也可以写入文件。提前致谢。
采纳答案by Shawn Chin
回答by Quamis
回答by J00MZ
Note you can add the -a
flag to tee
to append to the output file
请注意,您可以将-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