To allow us to select strings containing a specific pattern, the C-Shell supports wildcards: special characters that can replace part (or all) of a string. The most frequent use of wildcards is in command-line arguments. For instance, to copy every file whose name ends with .cpp in directory foo to the directory /tmp, we would write:

% cp foo/*.cpp /tmp

The wildcard characters and their meaning are:

Wildcard Meaning
* Matches any string, including the empty string
? Matches any single character
[start-end] Matches any character in the range specified by start and end.
[xy] Matches any character or string that starts with the character specified by x or y

When csh encounters a wildcard character that is not contained between single ['] or double ["] quotes, it performs a wildcard substitution. Because [*] matches any string, using [*] in the pathname foo/*.cpp applies the command cp to all files whose name ends with .cpp.

Also, as we have seen in the previous section, if we use an asterisk as an index to reference list elements, then the value is the list itself. We will see more examples that use wildcard characters this way in the upcoming sections.

Let us look at some more examples:

% ls -FR 
a.c b.c cc.c dir1/ dir2 

dir1: 
d.c e.e 

dir2: 
f.d g.c h.x i.y j.z 

% ls *.c 
a.c b.c cc.c 

% ls ?.c 
a.c b.c 

% ls [ac]* 
a.c cc.c 

% ls dir*/*.c 

dir1: 
d.c 

dir2 
g.c 

% ls dir2/[g-i]* 
g.c h.x i.y