The "tee" Command in Linux: The Hidden Gem Every Tech Professional Should Know
If you’ve ever worked with Linux, chances are you’ve used commands like cat, grep, or echo. But there’s one powerful tool that often goes under the radar the "tee" command. It’s simple, efficient, and can save you a lot of time when dealing with command-line tasks. Let’s break it down, so that even beginners can understand what "tee" does, why it’s useful, and how to use it. What is the "tee" Command? The "tee" command is like a splitter for your command output. Normally, when you run a command, the result appears on your screen. But what if you want to see the output AND save it to a file at the same time? That’s exactly what "tee" does? it copies the output to a file while also displaying it on your screen. Why is this useful? Saves command output for future reference Helps log information without losing visibility Useful for debugging scripts and processes Allows multiple programs to use the same output Basic Use Case: Saving Output While Viewing It Let’s say you’re checking system disk usage with: df -h Normally, this shows results on your screen but doesn’t save them. With "tee", you can store the output in a file while still seeing it: df -h | tee disk_usage.txt Now: The disk usage appears on your screen The same output gets saved in disk_usage.txt This is useful for tracking storage changes over time. Example 2: Logging Errors While Running a Script Imagine you’re running a bash script, and you want to catch errors in a log file while still monitoring them in real time. ./backup_script.sh 2>&1 | tee error_log.txt "2>&1" redirects both errors and normal output "tee" ensures you see errors AND save them You can review error_log.txt later to troubleshoot This is great for debugging scripts without losing information. Example 3: Sending Output to Multiple Commands Another hidden power of "tee" is that it can send data to multiple commands at once. Let’s say you want to count the number of lines in a file while also saving its content: cat file.txt | tee copy.txt | wc -l "tee" saves a copy of file.txt into copy.txt "wc -l" counts the number of lines You get both a saved file and a processed result This is useful when analyzing data while storing backups. Why Should Tech Professionals Use "tee"? As you all today know, automation, debugging, and logging are essential skills. The "tee" command makes it easier to: Record command results for audits Debug issues in real-time while saving logs Share outputs across multiple tools It’s a small but powerful tool that can save hours of troubleshooting. Final Thoughts The "tee" command might not be the first tool you learn in Linux, but once you use it, you’ll wonder how you managed without it. Whether you’re saving logs, debugging errors, or analyzing data, "tee" makes everything more efficient. Try it and let me know what you think

If you’ve ever worked with Linux, chances are you’ve used commands like cat, grep, or echo. But there’s one powerful tool that often goes under the radar the "tee" command. It’s simple, efficient, and can save you a lot of time when dealing with command-line tasks.
Let’s break it down, so that even beginners can understand what "tee" does, why it’s useful, and how to use it.
What is the "tee" Command?
The "tee" command is like a splitter for your command output. Normally, when you run a command, the result appears on your screen. But what if you want to see the output AND save it to a file at the same time?
That’s exactly what "tee" does? it copies the output to a file while also displaying it on your screen.
Why is this useful?
- Saves command output for future reference
- Helps log information without losing visibility
- Useful for debugging scripts and processes
- Allows multiple programs to use the same output
Basic Use Case: Saving Output While Viewing It
Let’s say you’re checking system disk usage with:
df -h
Normally, this shows results on your screen but doesn’t save them.
With "tee", you can store the output in a file while still seeing it:
df -h | tee disk_usage.txt
Now:
- The disk usage appears on your screen
- The same output gets saved in disk_usage.txt
This is useful for tracking storage changes over time.
Example 2: Logging Errors While Running a Script
Imagine you’re running a bash script, and you want to catch errors in a log file while still monitoring them in real time.
./backup_script.sh 2>&1 | tee error_log.txt
- "2>&1" redirects both errors and normal output
- "tee" ensures you see errors AND save them
- You can review error_log.txt later to troubleshoot
This is great for debugging scripts without losing information.
Example 3: Sending Output to Multiple Commands
Another hidden power of "tee" is that it can send data to multiple commands at once.
Let’s say you want to count the number of lines in a file while also saving its content:
cat file.txt | tee copy.txt | wc -l
- "tee" saves a copy of file.txt into copy.txt
- "wc -l" counts the number of lines
- You get both a saved file and a processed result
This is useful when analyzing data while storing backups.
Why Should Tech Professionals Use "tee"?
As you all today know, automation, debugging, and logging are essential skills. The "tee" command makes it easier to:
- Record command results for audits
- Debug issues in real-time while saving logs
- Share outputs across multiple tools
It’s a small but powerful tool that can save hours of troubleshooting.
Final Thoughts
The "tee" command might not be the first tool you learn in Linux, but once you use it, you’ll wonder how you managed without it. Whether you’re saving logs, debugging errors, or analyzing data, "tee" makes everything more efficient.
Try it and let me know what you think