Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Globbing

Direct answer

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.

When to use this

Use it when a wildcard matches too much, too little or nothing.

First 30 seconds

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.

Operational verification

pattern on the command line → shell matches names in the directory → replaced by sorted matches (or left literal) → command runs

Evidence · next step

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
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it when a wildcard matches too much, too little or nothing.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

observation · 1
Key points

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').

Key checks
  • bash -x script.sh — trace each expanded command
  • bash -n script.sh — syntax check only
  • shellcheck script.sh — common bugs and quoting problems
  • echo $? — 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 nullglob removes it or failglob makes the command fail.
  • A leading dot must be matched explicitly, unless dotglob is set.
  • extglob adds ?(p), *(p), +(p), @(p) and !(p).
  • globstar makes ** match recursively through directories.

Pattern syntax

PatternMatches
*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

OptionEffect
shopt -s nullglobNo match: the word disappears (good in for loops)
shopt -s failglobNo match: an error, and the command isn't run
shopt -s dotglob* also matches dotfiles
shopt -s nocaseglobCase-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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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:

PatternMatches
*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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

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%
Technical changelog & impact

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.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

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.

Aliases that resolve here
bash globbingshell wildcardspathname expansionbash globstar
Embedded reference data

Quick lookup tables

Globbing operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Globbing.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateGlobbing 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 verificationPin 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 chainglob pattern + cwd → shell glob options/locale → directory entries → pathname matches/sort → final argv → target command → filesystem outcomeTrace requested/configured state through effective state to the observed workload result.
Failure boundaryGlobbing 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 evidenceCorrelated 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 outcomeUse this observation only for the specific claim it actually supports.
Evidence limitIt 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 checkContinue 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 boundaryGlobbing
Topic pathShell & Bash → Globbing
Runtime stateGlobbing 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 chainglob 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 boundaryGlobbing 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 ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?