Quiz Entry - updated: 2026.07.14
What is shell expansion (globbing) and what are the basic wildcards?
Globbing is the shell expanding wildcard characters like * and ? into matching filenames before the command runs — so rm *.tmp is really rm handed the full list of .tmp files.
* The glob wildcard set the shell expands before the command ever runs. *
The crucial mental model: the command never sees the wildcard. The shell expands the pattern against existing filenames first, then passes the resulting names as arguments. By the time ls *.pdf runs, ls is invoked as ls report.pdf notes.pdf — it has no idea a * was ever involved.
| Pattern | Matches | Example |
|---|---|---|
* |
Any run of characters (incl. none) | *.txt → all .txt files |
? |
Exactly one character | file?.txt → file1.txt, fileA.txt |
[abc] |
One character from the set | file[123].txt |
[!abc] / [^abc] |
One character not in the set | file[!0-9].txt |
[a-z] |
One character in the range | file[a-c].txt |
ls *.pdf # every PDF here
rm *.tmp # delete all .tmp files
cp /etc/*.conf ~/backup/ # copy every .conf in /etc
Two consequences of "shell expands first" that bite people:
- No matches → the literal pattern is passed through. If no file matches
*.xyz, the command receives the raw text*.xyz(in default bash), often producing a confusing "No such file" error. - To stop expansion, quote it.
find . -name "*.txt"quotes the pattern so the shell leaves it alone andfinddoes the matching itself. Unquoted, the shell would expand it prematurely against the current directory.
Go deeper:
glob(7) — Linux manual page —
*,?,[...], ranges and negation, including the "no match → literal pattern" rule.