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.

40–50 min Week 3 · Productivity, storage, packages, networking Ubuntu terminal
Your outcome: Patterns like *.txt become helpful time savers rather than confusing symbols.
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 folder

Creates 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 folder

Shows 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

Caution

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

Run from ~/linux-practice

rm -rf glob-lab

Put it into practice

  1. 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.

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

Your practice, your pace

Loading saved progress…

Discussion

Continue the conversation about this guide. Loading comments connects to GitHub Discussions through giscus.

Open community discussions on GitHub

Check before you copy

This command needs care. Read its context, confirm the target and location, and keep a recovery path.

Copying does not run a command.