Yesterday, I bumped into this command called tee, and I thought, “Huh, what’s this all about?” So, I did what any curious person would do – I messed around with it!
First Steps: What is ‘tee’ Anyway?
It turns out, tee is like a splitter for your terminal. Normally, when you run a command, the output goes straight to your screen. But with tee, you can send that output to your screen AND save it to a file at the same time. Think of it like a T-junction in a pipe.
My Little Experiment
I started simple. I had this file, ‘my_long_*’, filled with a bunch of random stuff. Usually, I’d use cat to see what’s inside:
cat my_long_*
But then I thought, “Let’s use tee!” So I typed:
cat my_long_* tee *
See that little thing? That’s a pipe. It takes the output from cat and sends it to tee.
tee then did its magic – it showed me the contents of ‘my_long_*’ on my screen, just like cat would, BUT it also saved the exact same thing to a new file called ‘*’.
Getting a Bit Fancier
Then I got a little bolder. What if I wanted to add more stuff to ‘*’ without erasing what was already there? Easy peasy!
echo "Adding some more text!" tee -a *
That -a is the key. It tells tee to “append” – basically, to tack the new stuff onto the end of the file instead of overwriting it.
Real-World Use?
I can see this being super handy when I’m running some long command and I want to both watch what’s happening AND keep a record of it for later. No more copy-pasting from the terminal!
Wrapping Up
So, that was my little adventure with tee. It’s not the flashiest command, but it’s definitely one of those little tools that can make life a bit easier. If you have any commands you want me to try please do tell!