[命令] Linux 命令 tee (将输出内容保存到文件里)

内容一:tee 命令的格式

# tee [option] [file]......

内容二:tee 命令的选项

1) -a 或者 –append 将输出内容添加到文件里内容的末尾
2) -i 或者 –ignore-interrupts 忽略中断信号
3) –help 显示帮助信息
4) –version 显示版本信息

内容三:tee 的使用案例

3.1 将输出内容添加到另一个文件里内容的末尾

# echo 'tee test' | tee -a test.txt
tee test
# tail -1 test.txt
tee test

(补充:这里以将输出内容 ‘tee test’ 添加到另一个文件 test.txt 里内容的末尾为例)

3.2 将文件内容添加到另一个文件里内容的末尾

# cat test1.txt | tee -a test2.txt
test1
# tail -1 test2.txt
test1

(补充:这里以将 test1.txt 文件里的内容添加到另一个文件 test2.txt 里内容的末尾为例)

3.3 将输出内容变成另一个文件里的所有内容

# echo 'tee test' | tee test.txt
tee test
# cat test.txt
tee test

(补充:这里以将输出内容 ‘tee test’ 变成另一个文件 test.txt 里的所有内容为例)

3.4 将文件内容变成另一个文件里的所有内容

# cat test1.txt | tee -a test2.txt
test1
# cat test2.txt
test1

(补充:这里以将 test1.txt 文件里的内容变成另一个文件 test2.txt 里的所有内容为例)