Filename Globbing

Before the shell passes arguments to an external command or interprets a built-in command, it scans the command line for certain special characters and performs an operation known as filename globbing . Filename globbing resembles the processing of wildcards used in MS-DOS commands, but it’s much more sophisticated. Table 13-1 describes the special characters, known as filename metacharacters, used in filename globbing.

Table 13-1. Filename metacharacters

Metacharacter

Function

*

Matches a string of zero or more characters

?

Matches exactly one character

[a bc...]

Matches any of the characters specified

[a-z]

Matches any character in the specified range

[ !abc...]

Matches any character other than those specified

[!a-z]

Matches any character not in the specified range

~

The home directory of the current user

~userid

The home directory of the specified user

~+

The current working directory

~-

The previous working directory

In filename globbing, just as in MS-DOS wildcarding, the shell attempts to replace metacharacters appearing in arguments in such a way that arguments specify filenames. Filename globbing makes it easier to specify names of files and sets of files.

For example, suppose the current working directory contains the files file1, file2, file3, and file04. Suppose you want to know the size of each file. The following command reports that information:

            ls -l file1 file2 file3 file04

However, the following command reports ...

Get Learning Red Hat Linux, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.