Linux中tee命令的使用

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)


發佈了65 篇原創文章 · 獲贊 27 · 訪問量 58萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章