Tee Command Basics
What is the Tee Command?
The tee
command is a powerful utility in Linux that allows you to simultaneously display command output on the terminal and save it to a file. It acts like a "T-junction" in command pipelines, splitting the output stream into two directions.
Basic Syntax
The basic syntax of the tee
command is straightforward:
command | tee [options] file
Key Features
- Writes output to both standard output and one or more files
- Supports multiple file outputs
- Provides options for appending or overwriting files
Simple Examples
Basic Output Redirection
ls | tee directory_list.txt
This command lists directory contents and simultaneously saves the output to directory_list.txt
.
Appending to a File
echo "New log entry" | tee -a logfile.txt
The -a
option appends output to an existing file instead of overwriting it.
Command Options
Option |
Description |
-a |
Append to file instead of overwriting |
-i |
Ignore interrupt signals |
Workflow Visualization
graph LR
A[Command Output] --> B[Terminal Display]
A --> C[File Storage]
B & C --> D[tee Command]
Use Cases
- Logging command outputs
- Debugging scripts
- Preserving command results while viewing them
Pro Tip for LabEx Users
When working in LabEx environments, tee
can be particularly useful for capturing and reviewing command outputs during learning and practice sessions.