在終端儲存輸出結果(日誌輸出)| 詳細應用 | Shell
阿新 • • 發佈:2022-12-10
問題:如何將Shell執行的程式結果儲存,方便之後檢視。
解決方式:
一、tee模組
在terminal端儲存簡單命令的結果
(1)覆蓋日誌檔案
command | tee ./path/mylog.log
(2)將輸出以追加的方式寫入日誌檔案
command | tee -a ./path/mylog.log
注意 :
命令中的豎直線|為管道符號,詳見管道符號 - 豎直線 | Shell
-a 是append的縮寫
.log是日誌檔案
在terminal端儲存指令碼執行的結果
# 直接覆蓋的方式
script.sh 2>&1 | tee ./path/mylog.log
# 以追加的方式
script.sh 2>&1 | tee -a ./path/mylog.log
注意:
2>&1 將輸出檔案1和2合併
二、輸出重定向方式
(1)覆蓋的方式
command > ./test.txt
(2)追加的方式
command >> ./test.txt
Sany 何燦
關注
————————————————
版權宣告:本文為CSDN博主「Sany 何燦」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本宣告。
原文連結:https://blog.csdn.net/SanyHo/article/details/109412861