Filename Expansion
Another way to save time in your commands is to use special characters to abbreviate filenames. You can specify many files at once by using these characters. This feature of the shell is sometimes called “globbing.”
MS-DOS provides a few crude features of this type. You can use a question mark to mean “any character” and an asterisk to mean “any string of characters.” Unix provides these wildcards too, but in a more robust and rigorous way.
Let’s say you have a directory containing the following C source files:
$ ls
inv1jig.c inv2jig.c inv3jig.c invinitjig.c invpar.cTo list the three files containing digits in their names, you could enter:
$ ls inv?jig.c
inv1jig.c inv2jig.c inv3jig.c
The shell looks for a single character to replace the question mark.
Thus, it displays inv1jig.c, inv2jig.c, and
inv3jig.c, but not invinitjig.c because that name
contains too many characters.
If you’re not interested in the second file, you can specify the ones you want using brackets:
$ ls inv[13]jig.c
inv1jig.c inv3jig.cIf 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 ...