tee oolong

tee oolong

ginger tea | February 5th, 2025


Today, I wanted to mess around with something I hadn’t really used before, a command called “tee”. I was curious about what it could do, especially when it came to redirecting output in my terminal.

So, I started by just typing in tee all by itself in the command line, just to see what would happen. Predictably, it just kind of sat there, waiting for some input. I typed a few lines, and sure enough, each line I entered got echoed back to the terminal. Okay, basic stuff.

Experimenting with Redirecting Output

Then, I decided to try redirecting the output to a file. I used the command tee *. I typed in some more lines, and as expected, they were displayed in the terminal. But here’s the cool part, it also saved those lines into the “*” file. I checked the file using cat *, and there it was, everything I had typed. Neat!

Next, I thought, what if I want to append to an existing file instead of overwriting it? I already had “*” with some content, so I used tee -a *. I typed a few more lines and checked the file again. And just like that, the new lines were added to the end of “*” without erasing the previous content. Awesome!

tee oolong

Using Tee with Pipes

But I didn’t stop there. I wanted to see how tee works with pipes. So I tried something like ls -l tee file_*. What this did was it took the output of ls -l, displayed it in the terminal, and simultaneously saved it into “file_*”. Super handy for when you want to see the output right away but also save it for later.

  • First, I just tried tee alone.
  • Then, I redirected output to a new file using tee *.
  • After that, I appended to the file with tee -a *.
  • Finally, I used tee with a pipe, like ls -l tee file_*.

I even tried something a bit more complex like find . -name “.txt” tee txt_* xargs grep “important”. This command found all text files, listed them in the terminal, saved the list to “txt_*”, and then used xargs to search for the word “important” in those files. All of this happened at the same time, which was pretty cool to see.

Honestly, playing around with tee was way more fun than I expected. It’s such a simple command, but it’s incredibly useful for handling output in different ways. I can definitely see myself using this a lot more in the future.

Leave a Reply

Your email address will not be published. Required fields are marked *