Linux命令之tee命令使用实例

番茄系统家园 · 2023-05-07 12:17:32

名称: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 boot3.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 boot3.2.0-24-generic Sat Jan 10 14:17 - 19:24(05:07)
reboot system boot3.2.0-24-generic Fri Jan9 20:50 - 22:50(01:59)
cwjy1202 pts/0:0 Thu Jan8 22:08 - 23:16(01:08)
reboot system boot3.2.0-24-generic Thu Jan8 21:45 - 23:17(01:31)
cwjy1202 pts/2:0 Wed Jan7 23:22 - 00:27(01:05)
cwjy1202 pts/0:0 Wed Jan7 23:04 - 00:27(01:23)
reboot system boot3.2.0-24-generic Wed Jan7 23:03 - 00:27(01:23)
cwjy1202 pts/2:0 Tue Jan6 23:10 - 23:46(00:36)
cwjy1202 pts/0:0 Tue Jan6 22:32 - 23:46(01:13)
reboot system boot3.2.0-24-generic Tue Jan6 19:32 - 23:46(04:13)
cwjy1202 pts/0:0 Tue Jan6 00:24 - 00:46(00:21)
reboot system boot3.2.0-24-generic Mon Jan5 20:59 - 00:46(03:47)
cwjy1202 pts/0:0 Sat Jan3 20:33 - 00:39(04:06)
cwjy1202 pts/0:0 Sat Jan3 19:23 - 19:24(00:00)
reboot system boot3.2.0-24-generic Sat Jan3 19:12 - 00:41(05:28)
cwjy1202 pts/2:0 Sat Jan3 14:58 - 17:04(02:05)
cwjy1202 pts/1:0 Sat Jan3 14:57 - 17:04(02:07)
reboot system boot3.2.0-24-generic Sat Jan3 14:54 - 17:05(02:10)/p

wtmp begins Fri Jan2 17:17:32 2015

注意:上名的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

免责声明: 凡标注转载/编译字样内容并非本站原创,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如果你觉得本文好,欢迎推荐给朋友阅读;本文链接: https://m.nndssk.com/xtwt/187348tlnJa6.html
猜你喜欢
最新应用
热门应用