Suggested day 1820–30 minutesCaution

Mission 3 of 5

Shell Expansions and Wildcards

Select groups of files predictably before performing an action.

Use brace expansion, globbing, command substitution, arithmetic expansion, and defaults.

Outcome: Patterns like *.txt become helpful time savers rather than confusing symbols.

Mental model

Understand what is happening

The shell expands patterns before commands run.

Globs match filenames; regex is different.

Always echo a pattern first if you are unsure.

Guided lab

Work through the mission

1

Brace expansion

Safe

Creates multiple practice files quickly.

Terminal
echo file_{1..5}.txt
touch file_{1..5}.txt
ls file_*.txt
2

Globbing lab

Safe

Shows common filename patterns.

Terminal
mkdir -p glob-lab
cd glob-lab
touch a.txt b.txt c.txt 1.txt 22.txt abc.txt
echo *.txt
echo ?.txt
echo [ab].txt
cd ..
3

Safe cleanup

Caution

Removes only the glob-lab folder created in the sandbox.

Terminal
rm -rf glob-lab

Checkpoint

Verify the mission

The expanded names match the intended files.

Try it yourself

One step without a recipe

Create red_file.txt, green_file.txt, blue_file.txt and match them with *file.txt.

Need a hint?

Before you run `rm` with a wildcard, run `echo` with that same pattern. If the file list looks wrong, your pattern is wrong. Two seconds of checking saves two hours of recovery.

Explain it back

Before you move on

  • What does ?.txt match?
  • Why should you echo a risky glob first?

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