Filename Substitution (Globbing)

The most common type of substitution is filename substitution or globbing. Globbing is the method by which the shell expands a string containing globbing meta-characters or wildcards into a list of filenames. Table 9.1 lists the wildcards used in globbing.

Table 9.1. Globbing Meta-Characters (Wildcards)
Wildcard Description
* Matches zero or more occurrences of any character
? Matches one occurrence of any character
[characters] Matches one occurrence of any of the given characters

Any command or script that operates on files can take advantage of globbing. The examples in this section use the ls command because its output clearly illustrates the results of globbing.

The * Meta-Character

The simplest form of filename ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.