Extended Pattern Matching
Operator |
Meaning |
*(patternlist) |
Matches zero or more occurrences of the given patterns. |
+(patternlist) |
Matches one or more occurrences of the given patterns. |
?(patternlist) |
Matches zero or one occurrences of the given patterns. |
@(patternlist) |
Matches exactly one of the given patterns. |
!(patternlist) |
Matches anything except one of the given patterns. |
Some examples of these include:
• *(alice|hatter|hare) would match zero or more occurrences of alice, hatter, and hare. So it would match the null string, alice, alicehatter, etc.
• +(alice|hatter|hare) would do the same except not match the null string.
• ?(alice|hatter|hare) would only match the null string, alice, hatter, or hare.
• @(alice|hatter|hare) would only match alice, hatter, or hare.
• !(alice|hatter|hare) matches everything except alice, hatter, and hare.
The values provided can contain shell wildcards too. So, for example, +([0-9]) matches a number of one or more digits. The patterns can also be nested, so you could remove all files except those beginning with vt followed by a number by doing rm !(vt+([0-9])).