歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Linux命令之tee命令使用實例

名稱: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

Copyright © Linux教程網 All Rights Reserved