Glob Patterns: What *, ?, and [ ] Match in the Shell
A glob pattern is a short wildcard expression the shell expands into file names: * matches any string, ? matches exactly one character, and [ ] matches one character from a set. Globs are not regular expressions, and the shell, not the command, does the matching.
Quick answer
If your notes live in a folder of plain text files, three lines cover most selections:
ls *.md # every Markdown file
ls note-?.md # note-1.md, note-a.md, but not note-10.md
ls 2026-[01]*.md # names starting 2026-0 or 2026-1The rest of this article explains what each symbol matches, where globs refuse to match, and how they differ from regex.
How it actually works
* and ?: any string, one character
The glob(7) manual page defines a wildcard pattern as one containing ?, *, or [. An unbracketed ? matches any single character. An unbracketed * matches any string, including the empty string.
With these files in a folder:
Law.md Laws.md Lawyer.md GrokLaw.mdLaw* matches Law.md, Laws.md, and Lawyer.md, but not GrokLaw.md, because a glob has to match the whole name from the first character to the last. Because * can match nothing, Law* also matches a file named just Law. ? is stricter: ?at matches cat and bat but not at, since it needs exactly one character there.
Brackets: sets, ranges, classes, and negation
[...] matches one character from the enclosed set. A range such as [0-9] or [A-Fa-f0-9] is shorthand for listing every character in it. Letter[0-9] matches Letter0 through Letter9, but not Letter10, because the bracket matches only one character.
To negate a set, start it with !. [!C]at matches Bat and cat but not Cat. The POSIX specification models the bracket on regex brackets but says ! replaces ^ as the negation marker, and that a bracket starting with an unquoted ^ gives unspecified results. If you are used to [^abc] from regex, switch to [!abc] in globs.
Named classes also work inside brackets, such as [[:digit:]] or [[:lower:]]. The man page lists alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, and xdigit. Be careful with letter ranges: the manual notes that POSIX defines a range by the current collating sequence, so [a-z] depends on your locale. Classes are the safer choice when that matters.
Dotfiles and slashes
Two rules catch people out. First, a leading period must be matched explicitly. The man page's own example: rm * will not remove .profile. *, ?, [!a], ranges, and classes all skip a leading dot. To include hidden files, write the dot yourself: .* or .git*.
Second, wildcards never match a slash, either. POSIX requires a / in a path to be matched by a / in the pattern, so globbing works one path component at a time: notes/*/*.md reaches two levels down, never more. A bracket can't contain a slash either; a[b/c]d only matches the literal name a[b/c]d.
Who expands the pattern
On Unix, the shell expands globs) before the program starts, so the program receives the matched names, not the pattern. That is why quoting matters. ls "*.md" passes a literal *.md to ls, which looks for a file with that exact name. Quoting is also how you hand a pattern to a program that does its own matching, such as find -name '*.md'; see our guide to the find command.
If nothing matches, POSIX says the pattern is left unchanged, so the command sees the literal text. In bash, shopt -s nullglob makes an unmatched pattern expand to nothing instead.
When to use it (and when to skip it)
Reach for a glob when you're selecting files by name: moving, listing, or archiving a batch of notes. It's short and easy to read.
Skip it when you're matching text rather than names. Wildcard patterns match file names, and a glob has no equivalent of the regex Kleene star. In a regex, * means zero or more of the preceding item; in a glob, * stands alone and means any string. Roughly, glob ? corresponds to regex . and glob * to .*, but a regex may match part of a string while a glob matches all of it. For searching inside files, use grep or ripgrep, and see regex flavors for how patterns vary between tools.
Two popular extras sit outside the POSIX table. Bash's ** (globstar) recurses through directories, and brace expansion like {a,b} is expanded before globbing. Both depend on your shell, so test them before you put them in a script. A related use of wildcards is .gitignore wildcards, which look similar but follow Git's own rules.
How Carets fits in
Plain text notes are just files, so the same patterns you use on the command line describe your whole collection: *.md for Markdown, 2026-* for date-first names. Carets is a native editor for iPhone, iPad, and Mac that keeps your Markdown, plain text, and code as ordinary files, organized into files, projects, and tags. Shell snippets saved in a note get syntax highlighting, so a pattern like 2026-[01]*.md stays easy to read.
Your files stay plain text, portable and future-proof. Get Carets on the App Store for iPhone, iPad, and Mac.
Frequently Asked Questions
Why does ls * not show my dotfiles?
A leading period must be matched explicitly, so * skips names like .profile. Use .* or another pattern that starts with a dot.
Is [^abc] the same as [!abc] in a glob?
POSIX makes [^...] unspecified in wildcard patterns and uses ! as the negation marker. Some shells accept ^, but ! is the portable choice.
Does * match across directories?
No. *, ?, and bracket expressions never match a slash, so each path component is matched on its own. Bash's ** is an extension for recursive matching.
What happens if a glob matches nothing?
POSIX says the pattern is left unchanged, so the command receives the literal text. In bash, shopt -s nullglob makes it expand to nothing instead.