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

来源:互联网 发布:知乎机构号运营方案 编辑:程序博客网 时间:2024/04/26 08:31

一般有三种需求:
假如我要执行一个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

二者区别同上

add:2017年2月21日
如果我们需要将多个txt文件内容合并为一个文件:
只需要下面一行命令:

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

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

1 0