Using globs

* unquoted asterisk character on a command line has a special meaning to Bash: it means it should expand the word in which the character occurs to all of the matching filenames if possible, but (by default) to leave the word unchanged if there are no such matching files.

This can be confusing, and is best explained with a few examples. Suppose our current directory has the following filenames:

$ ls -a
.  ..  .bashrc  april  august  october  september

A glob by itself will expand to all the filenames that are not prefixed with a dot:

$ printf '%s\n' *
april
august
october
september

Note that the filenames are expanded in alphabetical order  or, more correctly, the order specified by your language environment's collation settings.

If there are other letters in the same word as a glob, they have to match the relevant filenames in the same position. We could get all the filenames starting with a with a*:

$ printf '%s\n' a*
april
august

Or the filenames ending in ber with *ber:

$ printf '%s\n' *ber
october
september

Or both  we can put two globs on the same line, and they will be expanded in order:

$ printf '%s\n' a* *ber
april
august
october
september

Rather than matching any number of characters, we can also match a single character with a question mark, ?:

$ printf '%s\n' ????ber
october

Note that here, october was printed but september was not, because only october matched the condition: four characters  no more, no less  followed immediately by three characters, ber.

Rather than matching any character with ?, you can also define valid sets of characters with the [...] syntax:

$ printf '%s\n' *[lr]
april
october
september

The pattern used here could be read as "any filename ending with l or r." Note that august was not printed, as it does not match. These sets can be inverted with an exclamation mark as the first character in the range:

$ printf '%s\n' *[!lr]
august

Now the pattern matches anything that does not end with l or r.

For brevity, these ranges can also be represented with hyphenated ranges, or character classes. Full details on these ranges are available under the "Pathname Expansion" heading in the bash manual page:

[a-z]
[0-9]
[[:alnum:]]