Linux tee命令

Linux tee命令用於讀取標準輸入的數據,並將其內容輸出成文件。html

在執行Linux命令時,咱們能夠把輸出重定向到文件中,好比 ls >a.txt,linux

這時咱們就不能看到輸出了,若是咱們既想把輸出保存到文件中,又想在屏幕上看到輸出內容,就能夠使用tee命令了。app

tee命令讀取標準輸入,把這些內容同時輸出到標準輸出和(多個)文件中,tee命令能夠重定向標準輸出到多個文件。要注意的是:在使用管道線時,前一個命令的標準錯誤輸出不會被tee讀取。less

tee指令會從標準輸入設備讀取數據,將其內容輸出到標準輸出設備,同時保存成文件。this

語法

tee [-ai][--help][--version][文件...]

參數spa

  • -a或--append  附加到既有文件的後面,而非覆蓋它.
  • -i或--ignore-interrupts  忽略中斷信號。
  • --help  在線幫助。
  • --version  顯示版本信息。

實例

使用指令"tee"將用戶輸入的數據同時保存到文件"file1"和"file2"中,輸入以下命令:htm

$ tee file1 file2                   #在兩個文件中複製內容 

以上命令執行後,將提示用戶輸入須要保存到文件的數據,以下所示:blog

My Linux #提示用戶輸入數據  My Linux #輸出數據,進行輸出反饋 

此時,能夠分別打開文件"file1"和"file2",查看其內容是否均是"My Linux"便可判斷指令"tee"是否執行成功。get


 

經常使用參數

格式:teeinput

只輸出到標準輸出,由於沒有指定文件嘛。

 

格式:tee file

輸出到標準輸出的同時,保存到文件file中。若是文件不存在,則建立;若是已經存在,則覆蓋之。(If a file being written to does not already exist, it is created. If a file being written to already exists, the data it previously
contained is overwritten unless the `-a' option is used.)

 

格式:tee -a file

輸出到標準輸出的同時,追加到文件file中。若是文件不存在,則建立;若是已經存在,就在末尾追加內容,而不是覆蓋。

 

格式:tee -

輸出到標準輸出兩次。(A FILE of `-' causes `tee' to send another copy of input to standard output, but this is typically not that useful as the copies are interleaved.)

 

格式:tee file1 file2 -

輸出到標準輸出兩次,同時保存到file1和file2中。


 

refs:

https://www.runoob.com/linux/linux-comm-tee.html

http://www.javashuo.com/article/p-rjasnfho-mk.html

相關文章
相關標籤/搜索