$ ls inv[13]jig.c
inv1jig.c inv3jig.c
If any single character within the brackets matches a file, that file
is displayed. You can also put a range of characters in the brackets:
$ ls inv[1-3]jig.c
inv1jig.c inv2jig.c inv3jig.c
Now we're back to displaying all three files. The hyphen means
"match any character from 1 through 3, inclusive." You could ask
for any numeric character by specifying 0-9, and any alphabetic
character by specifying [a-zA-Z]. In the latter case, two
ranges are required because the shell is case-sensitive. The order
used, by the way, is that of the ASCII character set.
$ ls inv*jig.c
inv1jig.c inv2jig.c inv3jig.c invinitjig.c
The asterisk actually means "zero or more characters," so if a file
named invjig.c existed, it would be shown, too.
Unlike MS-DOS, the Unix shells let you combine special characters and
normal characters any way you want. Let's say you want to look for
any source (.c) or object (.o) file that contains a digit.
The resulting pattern combines all the expansions we've studied in this
section:
$ ls *[0-9]*.[co]
Filename expansion is very useful in shell scripts (programs), where
you don't always know exactly how many files exist. For instance, you
might want to process multiple log files named log001, log002, and so
on. No matter how many there are, the expression log* will
match them all.