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

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

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

转自: 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

  • 无匹配
  • 无匹配
anonymous 说:
2024年1月17日 01:42

it's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information. Kissimmee Termite Control

anonymous 说:
2024年1月17日 01:44

Hmm… I interpret blogs on a analogous issue, however i never visited your blog. I added it to populars also i’ll be your faithful primer. Orlando Bed Bug Pest Control

anonymous 说:
2024年1月17日 01:46

In this case you will begin it is important, it again produces a web site a strong significant internet site: Oviedo Bed Bug Pest Control


登录 *


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