Capture command output to a file while still watching it on the terminal. 13.05.2026 | reading time: 3 min The `tee` command reads from standard input and writes the same data to standard output and one or more files, so he can both observe and save a program's output at once. Capture and view output at once Try this: run a command, save what you see, and inspect the file immediately: ```bash $ ls -l | tee listing.txt total 0 -rw-r--r-- 1 user user 0 May 13 12:00 file1 -rw-r--r-- 1 user user 0 May 13 12:00 file2 $ cat listing.txt total 0 -rw-r--r-- 1 user user 0 May 13 12:00 file1 -rw-r--r-- 1 user user 0 May 13 12:00 file2 ``` Append instead of overwrite with `-a`: `echo "more" | tee -a listing.txt`. Solve permission and pipeline problems When a file requires root to write, pipe through `sudo tee` rather than running a whole pipeline as root: `echo "127.0.0.1 host.local" | sudo tee -a /etc/hosts` preserves the pipeline flow and writes as root; combine `tee` with pipelines to log and filter at once, for example `make 2>&1 | tee build.log | grep -i error` to save a build log while searching for errors in real time. Power-user options and behavior Key options: `-a` appends, `-i` ignores SIGINT, and multiple filenames write to each; `tee` returns a nonzero status on write failure, so he can detect I/O errors in scripts; pair `tee` with process substitution `cmd | tee >(othercmd)` to feed the same output to another command concurrently. Tools that complement tee Use `sponge` to soak up input and write after processing, `script` to record full terminal sessions including interactive programs, and `pv` to monitor throughput when copying large streams; each fills a different niche when capturing, buffering or visualizing data flows. Learning next steps Start using `tee` in daily troubleshooting and logging tasks to build reliable pipelines; then expand skills into stream control and scripting to handle complex data flows, and consider formal certifications like CompTIA Linux+ or LPIC-1 with intensive exam preparation at bitsandbytes.academy to validate that knowledge. Join Bits & Bytes Academy First class LINUX exam preparation. utilities scripting backup troubleshooting filesystem