This article explains Bash globbing patterns for matching file and directory names using concise syntax, contrasting them with regular expressions.
In earlier lessons, we explored Bash parameter expansion—using operators like # and % (and their double variants ##/%%) to strip prefixes and suffixes from variable values. We even combined these with the wildcard * to broaden matches.
Globs (also called wildcards or pathname expansion patterns) differ from parameter expansion. They operate directly on filenames and strings in the shell, not on variable values.
Globs let you match file and directory names—or any arbitrary strings—using a concise pattern syntax. They’re simpler than regular expressions (no lookahead, named groups, etc.), but cover most everyday use cases:
In the following sections, we’ll apply these principles to real-world examples—filtering logs, batch-renaming files, and more. Let’s start by examining a directory of mixed files and crafting precise globs for each case.