在终端保存输出结果(日志输出)| 详细应用 | Shell

问题:如何将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

posted @ 2022-12-10 14:06  flytoyou  阅读(1046)  评论(0)    收藏  举报