ubuntu运行命令tee显示和保存为log

 

一般有三种需求: 
假如我要执行一个py文件

python class.py

1:将命令输出结果保存到文件log.log

python class.py |tee log.log

结果就是:屏幕输出和直接执行python class.py输出一样,但是输出同样被保存到了log.log文件中

2:将命令正确执行和错误的输出结果都保存到文件log.log

python class.py   2>&1 | tee  log.log

3:只需要保存到log.log文件中,屏幕标准输出不输出内容:

python class.py   2>&1 | tee  >log.log

或者

python class.py   | tee  >log.log

二者区别同上

如果我们需要将多个txt文件内容合并为一个文件: 
只需要下面一行命令:

cat 2007_train.txt 2007_val.txt 2012_*.txt > train.txt

在很多情况下都免去了再写一个python脚本来实现的烦恼。

posted on 2018-05-07 14:15  Maddock  阅读(2091)  评论(0编辑  收藏  举报

导航