六月丁香五月婷婷,丁香五月婷婷网,欧美激情网站,日本护士xxxx,禁止18岁天天操夜夜操,18岁禁止1000免费,国产福利无码一区色费

學習啦>學習電腦>操作系統(tǒng)>Linux教程>

linux tee命令使用詳解教程

時間: 志藝942 分享

  在執(zhí)行Linux命令時,我們既想把輸出保存到文件中,又想在屏幕上看到輸出內容,就可以使用tee命令。接下來是小編為大家收集的linux tee 命令使用詳解教程,希望能幫到大家。

  linux tee 命令使用詳解教程

  tee

  功能說明:讀取標準輸入的數(shù)據,并將其內容輸出成文件。

  語   法:tee [-ai][--help][--version][文件…]

  補充說明:tee指令會從標準輸入設備讀取數(shù)據,將其內容輸出到標準輸出設備,同時保存成文件。我們可利用tee把管道導入的數(shù)據存成文件,甚至一次保存數(shù)份文件。

  參   數(shù):-a 附加到既有文件的后面,而非覆蓋它。如果給予tee指令的文件名稱已經存在,預設會覆蓋該文件的內容。加上此參數(shù)后,數(shù)據會新增在該文件內容的最后面,而不會刪除原先之內容。

  -i 忽略中斷信號

  --help 在線幫助

  --version 顯示版本信息

  范   例:

  列出文本文件slayers.story的內容,同時復制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生成一個文件,包含你敲入的內容:

  復制代碼

  代碼如下:

  $tee testfile

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

  *把內容追加到文件的末尾行:

  復制代碼

  代碼如下:

  $tee -a testfile

  結果類似上,不過如果原來testfile有內容則不會覆蓋而是追加。

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

  復制代碼

  代碼如下:

  $tee -i testfile

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

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

  復制代碼

  代碼如下:

  $ls | tee test

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

  【描述】

  tee指令會從標準輸入設備讀取數(shù)據,將其內容輸出到標準輸出設備,同時保存成文件??梢杂糜诩认肟吹綐藴瘦敵觯窒雽藴瘦敵霰4娴轿募械那闆r。

  參數(shù):

  -a或--append  附加到既有文件的后面,而非覆蓋它.

  -i-i或--ignore-interrupts  忽略中斷信號。

  --help  在線幫助。

  --version  顯示版本信息。

  常用參數(shù)

  格式:tee

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

  格式:tee file

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

  格式: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 ~]#


看了“linux tee 命令使用詳解教程”還想看:

1.Linux系統(tǒng)中tee命令怎么用

2.Linux系統(tǒng)怎樣清理垃圾文件

3.CentOS等Linux系統(tǒng)清理系統(tǒng)垃圾和日志方法

linux tee命令使用詳解教程

在執(zhí)行Linux命令時,我們既想把輸出保存到文件中,又想在屏幕上看到輸出內容,就可以使用tee命令。接下來是小編為大家收集的linux tee 命令使用詳解教程,希望能幫到大家。 linux tee 命令使用詳解教程 tee 功能說明:讀取標準輸入的數(shù)
推薦度:
點擊下載文檔文檔為doc格式
2835901