亲宝软件园·资讯

展开

Linux命令之tee命令使用实例

人气:0

名称:tee
位置:/usr/bin/tee
权限:所有用户
作用:双向重定向,会同时将数据流送与文件和屏幕;而输出到屏幕的,就是stdout,可以让下一下命令继续处理。
用法:tee [OPTION]... [FILE]...
选项:

          -a, --append        append to the given FILEs, do not overwrite 

              追加


双向重定向,在写入文件last.list之后,还能输出到屏幕上。


last |tee last.list
cwjy1202 pts/0 :0 Sat Jan 10 22:14 still logged in
reboot system boot 3.2.0-24-generic Sat Jan 10 21:45 - 23:02 (01:16)
cwjy1202 pts/0 :0.0 Sat Jan 10 19:24 - down (00:00)
reboot system boot 3.2.0-24-generic Sat Jan 10 14:17 - 19:24 (05:07)
reboot system boot 3.2.0-24-generic Fri Jan 9 20:50 - 22:50 (01:59)
cwjy1202 pts/0 :0 Thu Jan 8 22:08 - 23:16 (01:08)
reboot system boot 3.2.0-24-generic Thu Jan 8 21:45 - 23:17 (01:31)
cwjy1202 pts/2 :0 Wed Jan 7 23:22 - 00:27 (01:05)
cwjy1202 pts/0 :0 Wed Jan 7 23:04 - 00:27 (01:23)
reboot system boot 3.2.0-24-generic Wed Jan 7 23:03 - 00:27 (01:23)
cwjy1202 pts/2 :0 Tue Jan 6 23:10 - 23:46 (00:36)
cwjy1202 pts/0 :0 Tue Jan 6 22:32 - 23:46 (01:13)
reboot system boot 3.2.0-24-generic Tue Jan 6 19:32 - 23:46 (04:13)
cwjy1202 pts/0 :0 Tue Jan 6 00:24 - 00:46 (00:21)
reboot system boot 3.2.0-24-generic Mon Jan 5 20:59 - 00:46 (03:47)
cwjy1202 pts/0 :0 Sat Jan 3 20:33 - 00:39 (04:06)
cwjy1202 pts/0 :0 Sat Jan 3 19:23 - 19:24 (00:00)
reboot system boot 3.2.0-24-generic Sat Jan 3 19:12 - 00:41 (05:28)
cwjy1202 pts/2 :0 Sat Jan 3 14:58 - 17:04 (02:05)
cwjy1202 pts/1 :0 Sat Jan 3 14:57 - 17:04 (02:07)
reboot system boot 3.2.0-24-generic Sat Jan 3 14:54 - 17:05 (02:10) </p> <p>wtmp begins Fri Jan 2 17:17:32 2015</p> <p>

注意:上名的tee命令并没有加选项 -a,这样默认文件将会被覆盖。

下面的例子,last的信息在写入文件last.list,同时还能被sed 命令处理


$ last |tee -a last.list| sed -n '1p'
cwjy1202 pts/0 :0 Sat Jan 10 22:14 still logged in

加载全部内容

相关教程
猜你喜欢
用户评论