【发布时间】:2012-05-28 09:31:45
【问题描述】:
我有一个 greps 一些数据的 shell 脚本。我想将结果打印到一个文件中,但是这样做会阻止结果显示在终端上。有没有办法既可以在屏幕上打印结果又可以写入文件。 提前致谢。
【问题讨论】:
我有一个 greps 一些数据的 shell 脚本。我想将结果打印到一个文件中,但是这样做会阻止结果显示在终端上。有没有办法既可以在屏幕上打印结果又可以写入文件。 提前致谢。
【问题讨论】:
将您的输出传递给tee 命令。
例子:
[me@home]$ echo hello | tee out.txt
hello
[me@home]$ cat out.txt
hello
注意echo的stdout被打印出来并写入到thrtee命令指定的文件中。
【讨论】:
请注意,您可以将 -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
【讨论】:
【讨论】: