Previous Next Chapter

Pattern Matching

You can work on several files or directories with one command using pattern matching. Special wildcard characters are used in command arguments to match characters in the file names. For example, use a wildcard character in a single command for copying or renaming all the files beginning with a specific letter, ending with the same extension, or residing in the same directory.

Wildcard Characters

The following list shows each wildcard character and the type of match it makes. In the list, a <p> indicates that either a single or multiple character string immediately adjacent to the wildcard is matched. To match a literal wildcard character, you must escape its wildcard meaning by prefacing it with an apostrophe (`). For example, `?, matches?, and ` ` (two single apostrophes) matches'.

?

Matches any single character.

#<p>

Matches zero or more occurrences of <p>.

<p1>|<p2>

Matches if either <p1> or <p2> matches.

-<p>

Matches everything but <p>.

(<p1><p2>...)

Parentheses group items together.

[<p>-<p>]

Square brackets delimit a character range.

%

Matches the null string (no characters).

`<p>

When <p> is wildcard character, matches that character.

The following examples indicate the matches that can be made using the entry in the left column.

A?B

Matches any three character names beginning with A and ending with B, such as AcB, AzB, and a3b.

A#BC

Matches any name beginning with A, ending with C, and having any number of Bs in between, such as AC, ABC, ABBC, ABBBC.

ABC#?

Matches any name beginning with ABC, regardless of what follows, such as ABCD, ABCDEF.info, or ABCXYZ.

#?XYZ

Matches any name ending in XYZ, regardless of what precedes it, such as ABCXYZ and ABCDEFXYZ.

A(B|C)D

Matches ABD or ACD.

~ (XYZ)

Matches anything but XYZ.

~ (#?XYZ)

Matches anything not ending in XYZ.

A#(BC)

Matches any name beginning with A followed by any number of BC combinations, such as ABC, ABCBC, and ABCBCBC.

A(B|D|%)#C

Matches ABC, ADC, AC (% is the null string), ABCC, ADCC, ACCC, and so forth.

[A-D]#?

Matches any name beginning with A, B, C, or D.

#?XYZ'?

Matches any name ending with XYZ?

The combination of #? matches any characters and is used most often. #? is equivalent to the * wildcard used by other computer systems. For example, to delete all the .info files in the Picture directory, enter:

1> DELETE Picture/#?.info

Caution:

Be careful not to accidentally delete the contents of a disk when using #?.

Top Previous Next Chapter