tee 命令是一个非常有用的工具,用于将标准输入的数据同时输出到标准输出(通常是终端)和一个或多个文件中。
基本语法如下:
command | tee [options] file1 [file2 ...]
option:
- 无参数时,默认是覆盖文件
- -a:追加到文件,而不是覆盖文件
- -i:忽略中断信号(如 SIGINT),使 tee 在接收到中断信号时继续运行,例如 Ctrl+C 终端输出
基本重定向: command | tee file
echo "Hello, World!" | tee output.txt
追加到文件:command | tee -a file
echo "Appending this line" | tee -a output.txt
忽略中断信号:command | tee -i file
echo "Ignoring interrupt signals" | tee -i output.txt
同时输出到多文件中:command | tee -a file1 file2
echo "Writing to multiple files" | tee file1.txt file2.txt