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.
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
Brace expansion
Creates multiple practice files quickly.
echo file_{1..5}.txt
touch file_{1..5}.txt
ls file_*.txtGlobbing lab
Shows common filename patterns.
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 ..Safe cleanup
Removes only the glob-lab folder created in the sandbox.
rm -rf glob-labCheckpoint
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?