濮阳杆衣贸易有限公司

主頁 > 知識庫 > linux tee 命令使用詳解(大量實例)

linux tee 命令使用詳解(大量實例)

熱門標簽:濟南智能語音電銷機器人加盟 無錫真人電銷機器人供應商 河南語音電銷機器人加盟公司 江西意向度高的羿智云外呼系統(tǒng) 易聯(lián)系統(tǒng)外呼營銷來回呼 電銷機器人怎么打卡 抖音商家地圖標注入駐店 如何找電銷機器人 無錫ai智能語音電銷機器人廠家

tee

  功能說明:讀取標準輸入的數(shù)據(jù),并將其內(nèi)容輸出成文件。
  語   法:tee [-ai][--help][--version][文件…]
  補充說明:tee指令會從標準輸入設(shè)備讀取數(shù)據(jù),將其內(nèi)容輸出到標準輸出設(shè)備,同時保存成文件。我們可利用tee把管道導入的數(shù)據(jù)存成文件,甚至一次保存數(shù)份文件。
  參   數(shù):-a 附加到既有文件的后面,而非覆蓋它。如果給予tee指令的文件名稱已經(jīng)存在,預設(shè)會覆蓋該文件的內(nèi)容。加上此參數(shù)后,數(shù)據(jù)會新增在該文件內(nèi)容的最后面,而不會刪除原先之內(nèi)容。
       -i 忽略中斷信號
       --help 在線幫助
       --version 顯示版本信息

  范   例:

  列出文本文件slayers.story的內(nèi)容,同時復制3份副本,文件名稱分別為ss-copy1、ss-copy2、ss-copy3:
  $ cat slayers.story |tee ss-copy1 ss-copy2 ss-copy3

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

【功能】

tee以標準輸入作為輸入,標準輸出和文件作為輸出。

【舉例】

tee file     //覆蓋
tee -a file    //追加

tee -        //輸出到標準輸出兩次
tee - -    //輸出到標準輸出三次

tee file1 file2 -    //輸出到標準輸出兩次,并寫到那兩個文件中
ls | tee file  

另:把標準錯誤也被tee讀取
ls "*" 2>1 | tee ls.txt

*用tee生成一個文件,包含你敲入的內(nèi)容:


復制代碼
代碼如下:

$tee testfile

這樣,會提示要你用標準輸入輸入內(nèi)容,然后敲回車會將你輸入的內(nèi)容寫入testfile和輸出到標準輸出,如果用[Ctrl]d結(jié)束輸入([Ctrl]c也行)。如果原來testfile有內(nèi)容,將會覆蓋。

*把內(nèi)容追加到文件的末尾行:


復制代碼
代碼如下:

$tee -a testfile

結(jié)果類似上,不過如果原來testfile有內(nèi)容則不會覆蓋而是追加。


*生成一個文件,敲入的時候,不接受中斷信號:


復制代碼
代碼如下:

$tee -i testfile

結(jié)果同testfile,不過不會接收中斷信號,只能用[Ctrl]d結(jié)束,而不能用[Ctrl]c了。

*執(zhí)行l(wèi)s列出目錄文件同時將輸出保存到文件test中:


復制代碼
代碼如下:

$ls | tee test

這樣,會像平時一樣執(zhí)行l(wèi)s命令并將當前目錄的文件名輸出到標準輸出。另外由于進行了tee命令,所以會生成一個test文件,這個test文件的內(nèi)容和標準輸出的內(nèi)容一樣。

【描述】

tee指令會從標準輸入設(shè)備讀取數(shù)據(jù),將其內(nèi)容輸出到標準輸出設(shè)備,同時保存成文件??梢杂糜诩认肟吹綐藴瘦敵?,又想將標準輸出保存到文件中的情況。

參數(shù):

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

常用參數(shù)
格式:tee

只輸出到標準輸出,因為沒有指定文件嘛。

格式:tee file

輸出到標準輸出的同時,保存到文件file中。如果文件不存在,則創(chuàng)建;如果已經(jīng)存在,則覆蓋之。(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中。如果文件不存在,則創(chuàng)建;如果已經(jīng)存在,就在末尾追加內(nèi)容,而不是覆蓋。

格式: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中。
 
使用示例補充:

示例一 tee命令與重定向的對比

[root@web ~]# seq 5 >1.txt
[root@web ~]# cat 1.txt
1
2
3
4
5
[root@web ~]# cat 1.txt >2.txt
[root@web ~]# cat 1.txt | tee 3.txt
1
2
3
4
5
[root@web ~]# cat 2.txt
1
2
3
4
5
[root@web ~]# cat 3.txt
1
2
3
4
5
[root@web ~]# cat 1.txt >>2.txt
[root@web ~]# cat 1.txt | tee -a 3.txt
1
2
3
4
5
[root@web ~]# cat 2.txt
1
2
3
4
5
1
2
3
4
5
[root@web ~]# cat 3.txt
1
2
3
4
5
1
2
3
4
5
[root@web ~]#

示例二 使用tee命令重復輸出字符串

[root@web ~]# echo 12345 | tee
12345

[root@web ~]# echo 12345 | tee -
12345
12345
[root@web ~]# echo 12345 | tee - -
12345
12345
12345
[root@web ~]# echo 12345 | tee - - -
12345
12345
12345
12345
[root@web ~]# echo 12345 | tee - - - -
12345
12345
12345
12345
12345
[root@web ~]#

[root@web ~]# echo -n 12345 | tee

12345[root@web ~]# echo -n 12345 | tee -
1234512345[root@web ~]# echo -n 12345 | tee - -
123451234512345[root@web ~]# echo -n 12345 | tee - - -
12345123451234512345[root@web ~]# echo -n 12345 | tee - - - -
1234512345123451234512345[root@web ~]#

示例三 使用tee命令把標準錯誤輸出也保存到文件

[root@web ~]# ls "*"
ls: *: 沒有那個文件或目錄
[root@web ~]# ls "*" | tee -
ls: *: 沒有那個文件或目錄
[root@web ~]# ls "*" | tee ls.txt
ls: *: 沒有那個文件或目錄
[root@web ~]# cat ls.txt
[root@web ~]# ls "*" 2>1 | tee ls.txt
ls: *: 沒有那個文件或目錄
[root@web ~]# cat ls.txt
ls: *: 沒有那個文件或目錄
[root@web ~]#

標簽:潛江 麗水 保定 山南 運城 衢州 新余 銅陵

巨人網(wǎng)絡(luò)通訊聲明:本文標題《linux tee 命令使用詳解(大量實例)》,本文關(guān)鍵詞  linux,tee,命令,使用,詳解,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《linux tee 命令使用詳解(大量實例)》相關(guān)的同類信息!
  • 本頁收集關(guān)于linux tee 命令使用詳解(大量實例)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    信宜市| 闽清县| 丽江市| 平罗县| 申扎县| 翼城县| 顺义区| 元氏县| 莱芜市| 三门县| 美姑县| 金山区| 阆中市| 惠安县| 马尔康县| 兰西县| 牟定县| 清水河县| 梁平县| 靖州| 海晏县| 滨海县| 舞阳县| 得荣县| 当雄县| 江北区| 福鼎市| 南城县| 乐安县| 烟台市| 寿阳县| 瑞丽市| 六安市| 辛集市| 泰宁县| 银川市| 会宁县| 大城县| 东源县| 皋兰县| 乌兰察布市|