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
Before this lab
What success looks like
- 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
- Work on copies of text data until you are confident that filters and substitutions behave as expected.
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
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
- Create a practice folder and enter it:
mkdir -p "$HOME/stream_lab"
cd "$HOME/stream_lab"- Create a file:
echo "alpha" > notes.txt- Append a second line:
echo "beta" >> notes.txt- Read the file:
cat notes.txt - Confirm that
>created or replaced the file, while>>added to the end.
Exercise G2: Capture an Error
- Run a command that will fail safely:
cat does-not-exist.txt- Run it again, but redirect the error:
cat does-not-exist.txt 2> errors.txt- Read the saved error:
cat errors.txtExercise G3: Build a Small Pipe
- Create a short file:
printf "INFO start\nWARN disk\nINFO done\n" > app.log- Filter it through a pipe:
cat app.log | grep "WARN"- Confirm that only the matching line survived the pipeline.
S Solo Task described, hints available - figure it out >
Exercise S1: Count Through a Pipe
- Reuse the same file:
cat app.log | wc -l- Confirm the line count.
Exercise S2: Save and See Output at the Same Time
- Run:
cat app.log | tee app-copy.log- 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:
- search for
WARNinsideapp.log - also search a second file that does not exist, such as
missing.log - save matching lines to
warn-matches.txt - save the error message to
warn-errors.txt
You should end up with one file for useful output and one file for failure output.
What to do next
Best next step LearningReturn to the related lesson if you want the concept explained more deeply.