Wildcards, Sets, and Brace Expansion

We’ve already used wildcards in a few places in this chapter, but there’s a lot more you can do with them than just using the * and ? operators to match strings and characters, respectively, as shown in Table 7-5.

Table 7-5. Wildcards and their meanings

Wildcard

Meaning

*

Any sequence of characters, except for a leading period

?

Any single character, except for a leading period

[set]

Any one of the characters in the set

[ch1-ch2]

Any one of the characters from ch1 through ch2

[^set]

Any single character not in the set

[^ch1-ch2]

Any single character not from ch1 through ch2

{ch,str,etc…}

Match all the characters and/or strings

Using Sets and Ranges

A set of characters placed within a pair of rectangular brackets can match a single character in a file or folder name. This is a more precise version of the ? single-character wildcard. For example, the set [abcdef] will match any of the six characters shown so that [abcdef]ark.txt will match the filenames bark.txt and dark.txt, as long as they both exist. You can also save on typing by using a hyphen to indicate a range of characters so that [a-f] is equivalent to [abcdef].

Another neat thing you can do with a set is force all upper- or all lowercase matches using the ranges [A-Z] or [a-z]. Or you can limit the matching to only alphabetical characters of either case (excluding digits and other characters) by using the set [a-zA-z]. And you can also use numbers in a range, as in [0-9].

Alternatively, you can ...

Get Ubuntu: Up and Running 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.