在终端上打印并同时写入文件? [英] Print on terminal and into file simultaneously?
本文介绍了在终端上打印并同时写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个可以捕获一些数据的shell脚本.我想将结果打印到文件中,但是这样做会阻止结果显示在终端上.有没有办法既可以在屏幕上打印结果,又可以写入文件. 预先感谢.
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.
推荐答案
将输出内容放置到 tee
命令.
Pipe your output to the tee
command.
示例:
[me@home]$ echo hello | tee out.txt
hello
[me@home]$ cat out.txt
hello
请注意,echo
的标准输出已打印并写入thr tee
命令指定的文件中.
Note that the stdout of echo
is printed out as well as written to the file specified by thr tee
command.
这篇关于在终端上打印并同时写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文