Frequently Asked Question

What does the tee command do?

tee reads from standard input and writes a copy of every byte to standard output and to one or more files you name on the command line. It is named after the plumbing fitting that splits one pipe into two, the data flows through, but a copy is siphoned off into the file. The classic use is make 2>&1 | tee build.log, which lets you watch a build's output scroll on the terminal in real time while also archiving the complete log to disk for later debugging.

A subtle but important option is tee -a, which appends to the file instead of truncating it. Without -a, tee clobbers the file just like >. People also use tee to write to files that need root privileges: echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward works because sudo elevates tee, whereas sudo echo 1 > /proc/sys/... runs echo as root but the redirection itself in your unprivileged shell, which fails.

Video

Further reading and video