Introduction
In the Linux environment, the ability to manipulate input and output streams is one of the cornerstones of command‑line power. The tee command sits at the heart of this philosophy, as it allows reading from standard input (stdin) while simultaneously duplicating that stream to one or more files and to standard output (stdout). This functionality is indispensable when you need to keep a record of what appears on screen without interrupting real‑time viewing.
How tee works under the hood
When a process sends data to its stdout, tee acts like a “T” in the pipe: it intercepts the flow, creates a copy, and sends it to each specified destination. The original continues unchanged, so any downstream process in the chain continues to receive the same data. In essence, tee does not consume or transform the information; it simply replicates it, making it safe to use in any situation requiring auditing or debugging.
Basic syntax and default behavior
The most elementary way to invoke tee is:
command | tee file.txt
In this example, the output of command is displayed in the terminal and saved to file.txt. If the file already exists, tee overwrites it by default. This overwrite behavior can be changed with the -a option, which will be explained later.
Most used options
- -a or –append: instead of truncating the file, it appends the output to the end, preserving previous content. Ideal for cumulative logs.
- -i or –ignore-interrupts: makes
teeignore interrupt signals such as SIGINT (Ctrl+C). This ensures the log file is closed properly even if the user cancels the preceding process. - –help: displays a brief help message with all available options.
- –version: prints the version of the program installed on the system.
Everyday usage examples
The true potential of tee is revealed in practical situations.
This post is also available in ESPAÑOL.