首页 > 系统相关 >在终端保存输出结果(日志输出)| 详细应用 | Shell

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

时间:2022-12-10 14:25:14浏览次数:48  
标签:输出 Shell mylog tee 日志 log

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

标签:输出,Shell,mylog,tee,日志,log
From: https://www.cnblogs.com/netflix/p/16971496.html

相关文章