Practice Use drills for recall and labs for real operating judgment.

LAB-TEXT-01 - The Unix Philosophy: Pipes & Redirection

Practice stdout, stderr, redirection, and pipes using safe local files and simple command output.

TXT Text Processing

The Unix Philosophy: Pipes & Redirection

Practice stdout, stderr, redirection, and pipes using safe local files and simple command output.

30 min BEGINNER LINUX Field-verified
Success criteria
  • Practice stdout, stderr, redirection, and pipes using safe local files and simple command output.
  • Repeat the workflow without copy-paste or step-by-step prompting.
Safety notes
  • Practice redirection inside disposable folders so mistakes with `>` do not damage anything important.

Part A: The Field Guide


What This Lab Is Really About

This lab is about controlling where command output goes.

You will practice four ideas:

  • writing output to a file
  • appending instead of overwriting
  • separating errors from normal output
  • piping one command into the next

Those four habits are the foundation of text-processing work in Linux.


Command Reference

Redirection and pipes

echo “hello” > notes.txt echo “second line” >> notes.txt cat missing.txt 2> errors.txt cat notes.txt | wc -l


Part B: The Drill Deck

Terminal required: create a disposable practice folder in your home directory.


G
Guided Step by step - type exactly this and compare the result
>

Exercise G1: Overwrite vs Append

  1. Create a practice folder and enter it:
mkdir -p "$HOME/stream_lab"
cd "$HOME/stream_lab"
  1. Create a file:
echo "alpha" > notes.txt
  1. Append a second line:
echo "beta" >> notes.txt
  1. Read the file: cat notes.txt
  2. Confirm that > created or replaced the file, while >> added to the end.

Exercise G2: Capture an Error

  1. Run a command that will fail safely:
cat does-not-exist.txt
  1. Run it again, but redirect the error:
cat does-not-exist.txt 2> errors.txt
  1. Read the saved error:
cat errors.txt

Exercise G3: Build a Small Pipe

  1. Create a short file:
printf "INFO start\nWARN disk\nINFO done\n" > app.log
  1. Filter it through a pipe:
cat app.log | grep "WARN"
  1. Confirm that only the matching line survived the pipeline.
S
Solo Task described, hints available - figure it out
>

Exercise S1: Count Through a Pipe

  1. Reuse the same file:
cat app.log | wc -l
  1. Confirm the line count.

Exercise S2: Save and See Output at the Same Time

  1. Run:
cat app.log | tee app-copy.log
  1. Confirm that the content appeared on screen and was also saved into app-copy.log.
M
Mission Real scenario - no hints, combine multiple skills
>

Mission M1: Save Matches, Save Errors Separately

Use one command to do all of the following:

  1. search for WARN inside app.log
  2. also search a second file that does not exist, such as missing.log
  3. save matching lines to warn-matches.txt
  4. save the error message to warn-errors.txt

You should end up with one file for useful output and one file for failure output.