曲径通幽论坛

标题: tee --- 输出并拷贝一个副本到文件 [打印本页]

作者: beyes    时间: 2008-12-29 22:17
标题: tee --- 输出并拷贝一个副本到文件
tee

把输出的一个副本输送到标准输出,另外一个副本拷贝到相应的文件中。

tee -a files
如果希望在看到输出的同时,也将其存入一个文件,那么这个命令就非常适合。这往往用在管道之后。

连续执行两次以下命令:
[root@localhost Desktop]# who | tee -a who.out
root     :0           2008-12-29 17:27
root     pts/1        2008-12-29 20:05 (:0.0)
[root@localhost Desktop]# who | tee -a who.out
root     :0           2008-12-29 17:27
root     pts/1        2008-12-29 20:05 (:0.0)

看一下 who.out 中的内容:
[root@localhost Desktop]# cat who.out
root     :0           2008-12-29 17:27
root     pts/1        2008-12-29 20:05 (:0.0)
root     :0           2008-12-29 17:27
root     pts/1        2008-12-29 20:05 (:0.0)

tee 命令不加 -a 参数,直接再输出一次:
[root@localhost Desktop]# who | tee who.out
root     :0           2008-12-29 17:27
root     pts/1        2008-12-29 20:05 (:0.0)

再看一下 who.out 中的内容:
[root@localhost Desktop]# cat who.out
root     :0           2008-12-29 17:27
root     pts/1        2008-12-29 20:05 (:0.0)

之前的内容被覆盖了,可见 -a 参数的意思是 apend。




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2