What are character classes in glob patterns?
Character classes like [[:digit:]] or [[:alpha:]] are named, locale-safe stand-ins for "any digit," "any letter," etc. — clearer and more portable than ranges like [0-9] or [a-z].
They match exactly one character, just like [abc], but instead of listing characters you name a category:
| Class | Matches |
|---|---|
[[:alpha:]] |
Any letter |
[[:digit:]] |
Any digit 0–9 |
[[:alnum:]] |
Letters and digits |
[[:lower:]] / [[:upper:]] |
Lower- / uppercase letters |
[[:space:]] |
Whitespace |
[[:punct:]] |
Punctuation |
ls [[:upper:]]* # files whose name starts with a capital letter
ls [[:alpha:]]*.txt # .txt files starting with any letter
Why prefer them over [a-z]? Ranges depend on locale and collation order. In some locales [a-z] quietly includes accented characters or even some uppercase letters, because the alphabetical ordering isn't the plain ASCII one you'd expect — a source of subtle, hard-to-debug bugs. [[:lower:]] means "lowercase letters" in every locale, full stop. So character classes are both more readable and more reliable, which matters most in scripts that run on machines you don't control.
Note the double brackets: the class itself is written [:digit:], and it must live inside a bracket expression, giving the [[:digit:]] form. Writing [:digit:] alone doesn't work.
Go deeper:
glob(7) — Linux manual page — bracket expressions and POSIX character classes like
[[:digit:]].