Mission 18 of 30
Shell Expansions and Wildcards
Select groups of files predictably before performing an action.
Use brace expansion, globbing, command substitution, arithmetic expansion, and defaults.
Your outcome: Patterns like *.txt become helpful time savers rather than confusing symbols.
Practice inside
Practice inside
~/linux-practice. Check your setup before you begin.
Prerequisite: History and Command Recall
.
What you’ll practice
- Use globs
- Use brace expansion
- Understand command and arithmetic expansion
The mental model
- The shell expands patterns before commands run.
- Globs match filenames; regex is different.
- Always echo a pattern first if you are unsure.
Try it in your terminal
Brace expansion
Safe in practice folderCreates multiple practice files quickly.
Run from ~/linux-practice
echo file_{1..5}.txt
touch file_{1..5}.txt
ls file_*.txt Globbing lab
Safe in practice folderShows common filename patterns.
Run from ~/linux-practice
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
CautionRemoves only the glob-lab folder created in the sandbox.
Run from ~/linux-practice
rm -rf glob-lab Put it into practice
- Create red_file.txt, green_file.txt, blue_file.txt and match them with *file.txt.
Check your result
The expanded names match the intended files.
Common mistakes
- You type `rm *.txt` and watch files you wanted to keep disappear. The glob expanded to include more than you expected. Always echo the pattern first: `echo *.txt` shows you exactly what will match.
- You try `grep '*.txt'` and it finds nothing. Shell globs expand filenames before the command runs. Grep regex matches text patterns inside files. Different tools, different rules.
Check your understanding
Explain these in your own words. If you’re unsure, revisit the examples before moving on.
- What does ?.txt match?
- Why should you echo a risky glob first?
Your practice, your pace
Loading saved progress…