Linux tee命令詳解

linux tee命令的功能是從標準輸入讀取,再寫入標準輸出和文件,其使用語法是“tee [OPTION]… [FILE]…”,其中參數“-a –append”表示追加到文件,參數“-i –ignore-interrupts”表示忽略中斷信號,參數“-p”表示診斷寫入非管道的錯誤等。

Linux tee命令詳解

本教程操作環境:linux5.9.8系統、Dell G3電腦。

linux 命令:tee 詳解

tee 的功能是從標準輸入讀取,再寫入標準輸出和文件。

用法:tee [OPTION]… [FILE]…

-a, –append? ? ? ? ? ? ? ? ? ? ? ? 追加到文件

-i, –ignore-interrupts? ? ? ? ? ?忽略中斷信號

-p? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?診斷寫入非管道的錯誤

–output-Error[=MODE]? ? ? ? 設置輸出錯誤的方式,MODE 的選項在下邊

–help? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?幫助文檔

–version? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 版本信息

MODE:

warn? ? ? ? ? ? ? ? ? ?寫入遇到錯誤時診斷

warn-nopipe? ? ? ?寫入非管道遇到錯誤時診斷

exit? ? ? ? ? ? ? ? ? ? ?寫入遇到錯誤時退出

exit-nopipe? ? ? ? ?寫入非管道遇到錯誤時退出

如果沒有指定 –output-error,tee 會在寫入管道發生錯誤時立即退出,寫入非管道時診斷。

使用示例:

默認功能和追加功能:

[root@server dir]# echo 'This is a sentence.' | tee output This is a sentence.  [root@server dir]# cat output This is a sentence.  [root@server dir]# echo 'This is another sentence.' | tee -a output This is another sentence.  [root@server dir]# cat output This is a sentence. This is another sentence.  [root@server dir]# echo 'This is a unique sentence.' | tee output This is a unique sentence.  [root@server dir]# cat output This is a unique sentence.

同時寫入兩個文件:

[root@server dir]# tee a b they have the same content they have the same content ^C [root@server dir]# cat a they have the same content [root@server dir]# cat b they have the same content

相關推薦:《Linux視頻教程

? 版權聲明
THE END
喜歡就支持一下吧
點贊15 分享