linux 中 tee命令

 

tee命令 :同时标准输出保存文件

 

001、

复制代码
[root@PC1 test01]# ls
[root@PC1 test01]# seq 3 | tee a.txt     ## 标准输出的同时,保存文件
1
2
3
[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt
1
2
3
复制代码

 

002、同时将文件复制多份

复制代码
[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt                             ## 测试文件
1
2
3
[root@PC1 test01]# cat a.txt | tee aaa bbb ccc ddd       ## 同时将文件复制多份
1
2
3
[root@PC1 test01]# ls
aaa  a.txt  bbb  ccc  ddd
[root@PC1 test01]# cat a.txt
1
2
3
[root@PC1 test01]# md5sum *                           ## 验证
c0710d6b4f15dfa88f600b0e6b624077  aaa
c0710d6b4f15dfa88f600b0e6b624077  a.txt
c0710d6b4f15dfa88f600b0e6b624077  bbb
c0710d6b4f15dfa88f600b0e6b624077  ccc
c0710d6b4f15dfa88f600b0e6b624077  ddd
复制代码

 

003、将文件显示多次

复制代码
[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt
1
2
3
[root@PC1 test01]# cat a.txt | tee - -    ## 有几个横杠将显示 n + 11
2
3
1
2
3
1
2
3
复制代码

 

004、-a参数表示追加

复制代码
[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt
1
2
3
[root@PC1 test01]# wc -l a.txt | tee xxx    ## 标准输出,并保存只文件
3 a.txt
[root@PC1 test01]# cat xxx
3 a.txt
[root@PC1 test01]# wc -l a.txt | tee -a xxx   ## 标准输出,并追加
3 a.txt
[root@PC1 test01]# cat xxx       ## 查看追加结果
3 a.txt
3 a.txt
复制代码

 

005、利用tee命令来生成文件

a、tee + file

复制代码
[root@PC1 test01]# ls
[root@PC1 test01]# tee a.txt       ## tee + file
a b c d                            ## 输入换行符后会标准输出
a b c d
0 1 2 3
0 1 2 3
^C
[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt       ## 查看结果
a b c d
0 1 2 3
复制代码

 

b、 tee + file + 结束符

复制代码
[root@PC1 test01]# ls
[root@PC1 test01]# tee a.txt << EOF    ## tee + file + 结束符
> 00 11 22 33
> aa bb cc dd
> EOF
00 11 22 33
aa bb cc dd
[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt           ## 查看结果文件
00 11 22 33
aa bb cc dd
复制代码

 

参考:https://blog.csdn.net/carefree2005/article/details/121537513

 

posted @   小鲨鱼2018  阅读(227)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-06-22 R语言中实现在命令行中传参
2022-06-22 R语言中read.table中colClasses = "character"选项作用
2021-06-22 c语言中以10进制、8进制、16进制显示同一个数字
点击右上角即可分享
微信分享提示