同时在终端和文件中打印? [英] Print on terminal and into file simultaneously?

查看:18
本文介绍了同时在终端和文件中打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于 grep 一些数据的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆