tee - read from standard input and write to standard output and files
tee命令用于读取标准输入的数据,并将其内容输出成文件。
tee指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件。
语法:
tee [OPTION]... [FILE]...
tee [-ai][--help][--version][文件...]
参数:
- -a或--append 附加到既有文件的后面,而非覆盖它.
-
[root@oldboy oldboy]# cat new.txt|tee ls_list_tee.txt -a # -a相当于追加重定向 1-user01 2-user02 3-user03 4-user04 5-user05 [root@oldboy oldboy]# cat ls_list_tee.txt date_str.txt ls_list.txt name.txt new new.txt number.txt school.txt seq_1.txt sort_c.txt sort_t.txt sort_test.txt split_test.txt test.sh test.txt uniq.txt 1-user01 2-user02 3-user03 4-user04 5-user05
-
- -i或--ignore-interrupts 忽略中断信号。
示例:
[root@oldboy oldboy]# ls > ls_list.txt [root@oldboy oldboy]# cat ls_list.txt date_str.txt ls_list.txt name.txt new new.txt number.txt school.txt seq_1.txt sort_c.txt sort_t.txt sort_test.txt split_test.txt test.sh test.txt uniq.txt
# 既向屏幕输出ls命令的结果,并将结果重定向到文件ls_list_tee.txt中。 [root@oldboy oldboy]# ls|tee ls_list_tee.txt date_str.txt ls_list.txt name.txt new new.txt number.txt school.txt seq_1.txt sort_c.txt sort_t.txt sort_test.txt split_test.txt test.sh test.txt uniq.txt
tee命令同时向两个文件中输入数据:
[root@oldboy oldboy]# tee file1 file2 # 指定命令后,屏幕给输入的空间,输入一行显示2行,表示分别向两个文件内输入数据 input a line input a line 2 2 ^C [root@oldboy oldboy]# cat file1 file2 input a line 2 input a line 2 [root@oldboy oldboy]# cat file1 input a line 2