← 返回命令列表

Linux command

tee 命令

文件

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Write stdin to file and stdout

echo "text" | tee [file]

Append to file

echo "text" | tee -a [file]

Write to multiple files

echo "text" | tee [file1] [file2]

Write command output to file

[command] | tee [output.log]

Use with sudo

echo "text" | sudo tee [/etc/file]

Write to file and pipe

[command] | tee [file] | [another_command]

Suppress stdout

[command] | tee [file] > /dev/null

说明

tee reads from standard input and writes to both standard output and one or more files simultaneously. Named after the T-shaped pipe fitting in plumbing, it "splits" the data stream. Common uses include logging command output while still viewing it, saving intermediate pipeline results for debugging, and writing to files requiring elevated privileges via sudo. Without -a, tee overwrites existing files. With multiple files, the same content is written to all of them. If a FILE is -, tee copies again to standard output. Tee continues the pipeline—output goes to both files and stdout, allowing further processing with additional pipe stages.

参数

-a, --append
Append to files instead of overwriting
-i, --ignore-interrupts
Ignore SIGINT (interrupt signal)
-p
Operate in a more appropriate mode with pipes (default MODE: warn-nopipe)
--output-error=_mode_
Set behavior on write error (warn, warn-nopipe, exit, exit-nopipe)
--help
Display help and exit
--version
Display version and exit

FAQ

What is the tee command used for?

tee reads from standard input and writes to both standard output and one or more files simultaneously. Named after the T-shaped pipe fitting in plumbing, it "splits" the data stream. Common uses include logging command output while still viewing it, saving intermediate pipeline results for debugging, and writing to files requiring elevated privileges via sudo. Without -a, tee overwrites existing files. With multiple files, the same content is written to all of them. If a FILE is -, tee copies again to standard output. Tee continues the pipeline—output goes to both files and stdout, allowing further processing with additional pipe stages.

How do I run a basic tee example?

Run `echo "text" | tee [file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -a, --append do in tee?

Append to files instead of overwriting