【导读】
tee命令会将数据流分送到文件与屏幕(stdout)。
一 tee参数介绍
[root@achao achao]# tee --help
Usage: tee [OPTION]... [FILE]...
Copy standard input to each FILE, and also to standard output.
-a, --append append to the given FILEs, do not overwrite
-i, --ignore-interrupts ignore interrupt signals
--help display this help and exit
--version output version information and exit
If a FILE is -, copy again to standard output.
复制
二 参数-a以累加的形式追加到文件中
[root@achao achao]# rm -rf *
[root@achao achao]# ll
total 0
[root@achao achao]# head -3 /etc/passwd | tee demo.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@achao achao]# cat demo.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
复制
发现在屏幕上显示的同时并且生成了一个新文件deno.txt,将stdout的数据记录。
[root@achao achao]# ls /
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@achao achao]# ls / | tee demo.txt
bin
boot
dev
......
[root@achao achao]# cat demo.txt
bin
boot
dev
......
复制
发现以前记录的信息不见了呢!这个时候就需要加参数-a。
[root@achao achao]# head -3 /etc/passwd | tee demo.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@achao achao]# cat demo.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@achao achao]# head -3 /etc/group | tee -a demo.txt
root:x:0:
bin:x:1:
daemon:x:2:
[root@achao achao]# cat demo.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
root:x:0:
bin:x:1:
daemon:x:2:
[root@achao achao]#
复制
这样就以累加的形式记录下来了。在具体的生产环境中还是很重要的。有想法的同学们一定想起了重定向的功能的。这里简单回忆一下。
三 重定向的使用
标准输入(stdin):代码为0,使用<或<<;
标准输出(stdout):代码为1,使用>或>>;
标准错误输出(stderr):代码为2,使用2>或2>>;
1> : 以覆盖的方式将【正确的数据】输出到指定的文件或设备上;
1>> : 以累加的方式将【正确的数据】输出到指定的文件或设备上;
2> : 以覆盖的方式将【错误的数据】输出到指定的文件或设备上;
2>> : 已累加的方式将【错误的数据】输出到指定的文件或设备上;
更加详细的知识可以点击下发链接
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
RedHat Enterprise Linux 6.6静默安裝Oracle 11.2.0
dastone
68次阅读
2025-03-10 17:18:46
Oracle RHEL 5.8 安装
Albert Tan DBA 之路
47次阅读
2025-03-11 11:32:33
Linux中/proc/*代表的意义
watson
43次阅读
2025-03-02 12:38:34
LINUX(suse,redhat)双网卡绑定操作步骤
IT那活儿
34次阅读
2025-03-07 10:30:04
Linux中使用pwck/pwconv/pwunconv/chpasswd快速检查账号信息
watson
33次阅读
2025-03-06 10:45:12
oracle安装与配置
淡定
31次阅读
2025-03-18 10:58:16
银行卡归属地-BIN号与发卡行识别的实现逻辑
IP数据云
30次阅读
2025-03-13 16:55:49
Linux操作系统如何判断root用户密码的有效期
watson
29次阅读
2025-03-17 09:24:04
Linux中lsof命令详解使用
watson
29次阅读
2025-03-15 09:15:25
Linux中的xargs命令妙用
watson
29次阅读
2025-03-09 09:14:07