Tee 使用场景

Tee命令用来同时存储和展示其他命令的输出

1. 输出到Console同时写入文件

使用ls查看文件夹下内容:

$ ls
account  cache  crash 

同时需要保存到文件filelist.txt(否者需要ls > filelist.txt):

$ ls | tee filelist.txt
account
cache
crash
filelist.txt

查看filelist.txt中,会看到包含了上一条命令的输出:

2. 输出使用在多条命令中:

查看并备份当前crontab后,更新crontab内容(old->new)

$ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab
3. 使用append(默认覆盖)
$ ls | tee –a file

4, 多文件写

$ ls | tee file1 file2 file3
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容