// learn · linux · rhcsa · 10 min

Bash globbing and quoting.

Wildcards never reach the command — the shell expands them first. Watch what gets rewritten, and learn the three quoting styles that stop the shell from rewriting things you didn't mean it to.

Bash globbing and quoting animated tutorial. Shell pattern matching with wildcards, brace expansion, recursive globstar, and the three styles of quoting (single, double, backslash). Covers RHCSA EX200 shell objectives.
// globbing and quoting

Two of the most-misunderstood Bash features. Watch each example show what you typed, what the shell expanded it to, and what the command finally saw.

// before you start
you should know
  • ·Comfortable running basic commands (ls, cp, mv, rm)
  • ·Know how to set a variable (FOO=bar) and reference it ($FOO)
  • ·Helpful but not required: read the Command Line Essentials lesson first
by the end you'll

Predict what the shell expands a pattern to before pressing Enter. Choose the right quoting style for each situation.

pace: 10 minutes

bash — shell expansion preview
step 1 / 6

Globs: the shell rewrites your command before it runs

A glob (also called a wildcard) is a pattern the shell matches against existing filenames. The key idea: the shell expands the pattern into a list of real filenames before the command ever sees it. `*` matches zero or more characters (except a leading dot). `?` matches exactly one character.

// key insight

The command never sees your * or $VAR. The shell rewrites the line first, then runs the result. Globs are matched against existing filenames; braces are pure text substitution; quoting suppresses one or more of the rewrite steps. When something behaves strangely, ask "what is the shell handing to the command?" — that's the line you actually ran.

// exam-ready · the patterns and switches you must know
$*
$?
$[abc]
$[a-z]
$[!abc] / [^abc]
$**
${a,b,c}
${1..10} / {01..10}
$'literal'
$"$preserved"
$\$
$shopt -s dotglob
$shopt -s nullglob
$shopt -s globstar
$shopt -s nocaseglob
$set -f / set +f
// check yourself
4 quick questions
Q1

Your home directory contains .bashrc, .vimrc, notes.txt, and Documents/. What does `ls *` print?

Q2

How is `{a,b,c}` different from `[abc]`?

Q3

Which one of these prints your username, and which prints the literal string `$USER`?

Q4

Why is `for f in *.txt; do cp $f backup/; done` buggy when a filename contains a space?

These aren't graded — they're just for active recall, which is what actually makes the lesson stick.

🎮
// now exercise it

Try the Bash Command Challenge

Several challenges hinge on getting the glob or the quoting right. Reading is one thing — typing it yourself and seeing the result is what cements the rules.

play →
back to RHCSA trackall lessons