tee命令的作用像字母T一樣,很形象的表示了它的功能:它把輸出的一個副本輸送到標準輸出,另一個副本拷貝到相應的文件中。如果需要在輸出到文件的同時,也把信息顯示到屏幕上輸出,那這個命令就再合適不過了。
一般格式如下:
tee -a files
-a選項表示追加到文件末尾。
如:
[root@localhost practise]# who | tee who.log
root :0 2012-09-27 07:13
root pts/1 2012-09-27 07:13 (:0.0)
此時目錄下會包含一個who.log文件,如下:
[root@localhost practise]# cat who.log
root :0 2012-09-27 07:13
root pts/1 2012-09-27 07:13 (:0.0)
再執行以下命令:
[root@localhost practise]# who | tee -a who.log
root :0 2012-09-27 07:13
root pts/1 2012-09-27 07:13 (:0.0)
[root@localhost practise]# cat who.log
root :0 2012-09-27 07:13
root pts/1 2012-09-27 07:13 (:0.0)
root :0 2012-09-27 07:13
root pts/1 2012-09-27 07:13 (:0.0)