Use it when a wildcard matches too much, too little or nothing.
Globbing
Globbing is filename pattern matching by the shell: * matches any string, ? one character, [abc] a set, and ** (with globstar) any depth. The shell replaces the pattern with matching names before running the command.
1. echo <pattern> — what does it expand to?
2. Nothing matched → literal pattern passed; check with ls.
3. Hidden files missing → shopt -s dotglob.
4. Pattern meant for find/grep → quote it.
5. Then run the real command.
pattern on the command line → shell matches names in the directory → replaced by sorted matches (or left literal) → command runs
For Shell & Bash → Globbing, continue with the first unproven Topic check: Record cwd and relevant shopt settings before evaluating the pattern. If that boundary is healthy, advance to the adjacent check: Test the pattern against a representative directory including dotfiles, spaces, newlines and names beginning with dash. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
glob pattern + cwd → shell glob options/locale → directory entries → pathname matches/sort → final argv → target command → filesystem outcome
Healthy evidence: pattern expands to exactly the expected pathname set under known cwd/options and the consuming command treats those names as data rather than options.
Step 2 Verification and output interpretation Verify boundary
Existing fast checks for this Topic. - Record cwd and relevant shopt settings before evaluating the pattern.
- Test the pattern against a representative directory including dotfiles, spaces, newlines and names beginning with dash.
- Inspect expanded argv and use -- or safer command constructs when filenames can be parsed as options.
- For destructive commands, narrow the pattern and verify exact targets before execution, then read back remaining/changed paths.
Verification chain. glob pattern + cwd → shell glob options/locale → directory entries → pathname matches/sort → final argv → target command → filesystem outcome
Step 3 Commands Verify boundary
ls *.log
shopt -s nullglob globstar
ls **/*.conf
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: dotfiles are omitted, unmatched patterns are passed literally, locale/order assumptions leak in, or an overbroad wildcard targets unintended files.
Step 5 Common mistakes Narrow the fault
- Unmatched globs passed literally.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
No match → Bash passes the pattern literally (unless nullglob is set), so rm *.log with no logs tries to delete a file called *.log. Globs do not match hidden files unless dotglob is set. Quote patterns you want passed to a program (find -name '*.log').
bash -x script.sh— trace each expanded commandbash -n script.sh— syntax check onlyshellcheck script.sh— common bugs and quoting problemsecho $?— exit code of the last command
ReferenceWhat it is1 section · depth on demand
Core model
Treat globbing as filesystem-dependent argument generation. Confirm current directory, pattern, hidden-file rules, case behavior and options such as nullglob, failglob, dotglob, globstar and extglob; then inspect the generated argument list before destructive operations.
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
Globbing evidence covers path selection under one directory state and shell configuration; concurrent changes or different cwd/options can produce a different target set.
In depth
Globbing: filename patterns and shell options
Unquoted *, ? and [ in a word trigger pathname expansion, and the shell replaces the word with the matching file names. The bash(1) manual page describes the default behaviour:
- With no match, the pattern stays unchanged, unless
nullglobremoves it orfailglobmakes the command fail. - A leading dot must be matched explicitly, unless
dotglobis set. extglobadds?(p),*(p),+(p),@(p)and!(p).globstarmakes**match recursively through directories.
Pattern syntax
| Pattern | Matches |
|---|---|
* | Any string, including empty |
? | Exactly one character |
[abc], [a-z] | One character from the set or range |
[!abc] / [^abc] | One character not in the set |
[[:digit:]] | Character classes |
**/ (globstar) | Any number of directories |
!(*.log) (extglob) | Everything except .log files |
@(jpg|png) (extglob) | Exactly one of the alternatives |
Options that change behaviour
| Option | Effect |
|---|---|
shopt -s nullglob | No match: the word disappears (good in for loops) |
shopt -s failglob | No match: an error, and the command isn't run |
shopt -s dotglob | * also matches dotfiles |
shopt -s nocaseglob | Case-insensitive matching |
shopt -s globstar | ** recursion |
Globs are not regular expressions
*.log in the shell means "names ending in .log". In a regex, * means "the previous item repeated". Tools such as find -name, case and [[ == ]] use glob patterns, while grep -E and [[ =~ ]] use regular expressions.
host$ ls
app.log app.log.1 db.log notes.txt .hidden
host$ echo *.log
app.log db.log
host$ for f in *.bak; do echo "found $f"; done
found *.bak
host$ shopt -s nullglob; for f in *.bak; do echo "found $f"; done; shopt -u nullglob
host$ shopt -s extglob; echo !(*.log*)
notes.txt
host$ shopt -s globstar; ls **/*.conf
host$ find /var/log -name '*.log' -mtime +30
Reading the loop example
Without nullglob, a pattern with no matches is passed on literally. The loop then runs once with the string *.bak. That's a common source of "file not found" errors in scripts, and nullglob (or a [[ -e $f ]] check) avoids it.
Documented example, not captured output.
How it works at runtime
Globbing is part of Shell & Bash → Globbing. Globbing is shell pathname expansion that maps wildcard patterns such as *, ?, bracket expressions and Bash glob options to filesystem pathnames before the target command starts.
Topic-specific state model. Globbing is shell pathname expansion that maps wildcard patterns such as *, ?, bracket expressions and Bash glob options to filesystem pathnames before the target command starts.
Interpretation rule. - Globs ≠ regular expressions.
- * ≠ hidden dotfiles by default in typical Bash settings.
- Pattern order ≠ arbitrary; pathname expansion commonly yields locale-sorted pathnames.
- No match ≠ empty list unless nullglob is enabled; the literal pattern can be passed to the command.
Quick reference
Globbing expands wildcards to matching file names before the command runs:
| Pattern | Matches |
|---|---|
* | Any string (not leading dot) |
? | One character |
[abc], [0-9] | One character from set |
{a,b} | Brace expansion (not a glob, always expands) |
** | Recursive (with shopt -s globstar) |
!(*.log) | Extended globs (shopt -s extglob) |
shopt -s nullglob dotglob globstar
ls /var/log/**/*.gz
for f in *.conf; do [[ -e $f ]] || continue; echo "$f"; done
Without nullglob, a pattern with no matches stays literal (*.conf), which breaks loops.
Limits and how it fails
Primary failure point. Globbing evidence covers path selection under one directory state and shell configuration; concurrent changes or different cwd/options can produce a different target set.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. Shell Expansion owns overall expansion order; File & Directory Management owns resulting filesystem operations; this Topic owns wildcard pathname selection.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Shell & Bash → Globbing. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.gnu.org/software/bash/manual/bash.html · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Globbing operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Globbing.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | Globbing is shell pathname expansion that maps wildcard patterns such as *, ?, bracket expressions and Bash glob options to filesystem pathnames before the target command starts. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin host/distribution + shell/version/mode → identify cwd/mount namespace + input/path/stream → preserve quoting/expansion and final argv → map fd/pipeline/process boundaries → inspect object/variable/status/signal state → make one minimal reversible change → read back effective state → repeat original consumer/script/workload test. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | glob pattern + cwd → shell glob options/locale → directory entries → pathname matches/sort → final argv → target command → filesystem outcome | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | Globbing proof covers path selection under one directory state and shell configuration; concurrent changes or different cwd/options can produce a different target set. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux file/text/shell evidence can establish this proof path: glob pattern + cwd → shell glob options/locale → directory entries → pathname matches/sort → final argv → target command → filesystem outcome | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove behavior outside the captured host, shell/session, cwd/namespace, input, process, filesystem, locale, time or workload scope. Globbing proof covers path selection under one directory state and shell configuration; concurrent changes or different cwd/options can produce a different target set. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven boundary: capture the exact shell-delivered argv/streams or resolved object, verify the effective target state, change only the demonstrated cause, then repeat the original consumer/script/workload and adjacent regression checks. | Continue to the next unresolved boundary while preserving the original test condition. |
Globbing · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | Globbing |
|---|---|
| Topic path | Shell & Bash → Globbing |
| Runtime state | Globbing is shell pathname expansion that maps wildcard patterns such as *, ?, bracket expressions and Bash glob options to filesystem pathnames before the target command starts. |
| Fast checks | - Record cwd and relevant shopt settings before evaluating the pattern. - Test the pattern against a representative directory including dotfiles, spaces, newlines and names beginning with dash. - Inspect expanded argv and use -- or safer command constructs when filenames can be parsed as options. - For destructive commands, narrow the pattern and verify exact targets before execution, then read back remaining/changed paths. |
| Verification chain | glob pattern + cwd → shell glob options/locale → directory entries → pathname matches/sort → final argv → target command → filesystem outcome Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | Globbing proof covers path selection under one directory state and shell configuration; concurrent changes or different cwd/options can produce a different target set. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |