Suggested day 720–30 minutesSafe in practice folder

Mission 2 of 5

Pipes and Filters

Build a small report by connecting focused commands.

Combine small commands into useful pipelines for sorting, counting, cutting, translating, and formatting text.

Outcome: You see the command line as a set of Lego bricks, not one giant memorization test.

Mental model

Understand what is happening

A pipe sends stdout from one command into stdin of the next.

sort | uniq is a classic pattern.

Filters transform text without opening an editor.

Guided lab

Work through the mission

1

Sort and count

Safe

Sorts lines and counts adjacent duplicates after sorting.

Terminal
cd ~/linux-practice
echo -e 'banana\napple\ncherry\napple' > fruits.txt
sort fruits.txt | uniq -c
2

Translate characters

Safe

Transforms text through a pipeline.

Terminal
echo 'Hello World' | tr 'a-z' 'A-Z'
echo 'Hello World' | tr ' ' '_'
3

Cut and align fields

Safe

Extracts fields and prints a simple table.

Terminal
echo 'Name:Age:City' > people.txt
echo 'Jane:25:London' >> people.txt
cut -d: -f1,3 people.txt
column -t -s: people.txt

Checkpoint

Verify the mission

The pipeline produces a sorted, counted report.

Try it yourself

One step without a recipe

Create animals.txt and count duplicates. Use cut to show selected fields.

Need a hint?

Think of each command in a pipe as a workstation on an assembly line. `sort` arranges the parts, `uniq` removes duplicates, `cut` picks what you need, and `tr` swaps labels. Build one station at a time. If the output looks wrong, remove the last pipe segment and check what's coming in.

Explain it back

Before you move on

  • What does the | symbol do?
  • Why is sort often used before uniq?

Shortcuts:Alt + ← previous lessonAlt + → next lessonAlt + H home? focus search