$
Lernen Linux-Handbuch
de
XP:0
Quest 27T-Junction
+250 XP

Splitting Output with tee

Interaktives Terminal für diese Quest starten→Keine Installation erforderlich • Läuft im Browser

Konzept & Übersicht

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.

1. Run 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.

Befehlssyntax-Referenz

Command / SyntaxDescription
echo "Build completed" | tee build.logWrite stdout to screen and file simultaneously
echo "PORT=8080" | sudo tee -a /etc/app.confSafely append to privileged file with sudo tee -a

Prüfungsziele

  • ○
    Write build status to build.log using tee
  • ○
    Append PORT=8080 to /etc/app.conf using sudo tee -a

Bereit für Quest 27?