Splitting Output with tee
Concept & Overview
In plumbing, a T-pipe splits a single water stream into two paths. In Linux, the tee command does the exact same thing with text streams: it reads standard input and writes it simultaneously to both the screen (stdout) and one or more files. E.g.: cmd | tee output.log.
Furthermore, tee solves a classic Linux permissions pitfall: running sudo echo "config" > /etc/app.conf fails because redirection > is handled by your unprivileged shell before sudo executes. Piping to sudo tee -a /etc/app.conf (where -a appends) runs tee with superuser privileges, safely writing to protected system files.
echo "Build completed" | tee build.log to view build output while capturing it in build.log.2. Append privileged configuration by running
echo "PORT=8080" | sudo tee -a /etc/app.conf.Command Syntax Reference
| Command / Syntax | Description |
|---|---|
echo "Build completed" | tee build.log | Write stdout to screen and file simultaneously |
echo "PORT=8080" | sudo tee -a /etc/app.conf | Safely append to privileged file with sudo tee -a |
Verification Objectives
These conditions will be automatically verified when you run commands inside the interactive terminal simulator:
- ○Write build status to build.log using tee
- ○Append PORT=8080 to /etc/app.conf using sudo tee -a
Ready to complete Quest 27?
Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.