When I want to redirect output to a file, I usually do this:
$ echo 'a' > b
$ cat b
a
However, I’ve seen people use tee instead of redirecting directly to a file. I’m wondering what the difference is. What I mean in this pattern:
$ echo 'a' | tee c
a
$ cat c
a
It doesn’t seem to be doing anything differently than a simple redirect. I know they are conceptually not the same thing, but I’m wondering why people would use one over the other.
Using
teelet’s you split the output. You can either view it (by directing stdout to the tty you are looking at) or pass it on to further processing. It is handy for keeping track of intermediate stages of a pipeline.