LinuxGem
此处为老的 LinuxGem,新版 LinuxGem 请移步 www.linuxgem.org

用 tee 同时重定向和显示信息

galeki posted @ 2007年12月10日 23:12 in Bash 和它的朋友们 , 2489 阅读

转自: http://linux.byexamples.com/archives/349/how-to-redirect-output-to-a-file-as-well-as-display-it-out/

bash 中的重定向操作符 “>" 大家肯定都很熟悉,如果你想把程序的输出存储到文件中去的话,很简单:

echo "hello world" > test.txt
但是这样程序的输出也没法在屏幕上显示出来了,如果我们想在屏幕上显示信息的同时,也把信息写到文件里该怎么办呢?

tee 就是解决的办法:

echo "hello world" | tee test.txt
追加操作符 “>>”,把程序输出的信息追加到文件的后面:

echo"hello world" >> test.txt
如果你也要在追加操作中同时显示信息的话,用 tee 的 -a 参数:

echo"hello world" | tee -a test.txt

  • 无匹配
  • 无匹配

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter