The standard file name globbing pattern to match a digit is
[0-9]. This matches a single digit:
To select only two of these:
For larger numbers than 9, brace expansion will be useful (but see note below for the difference between globbing patterns and brace expansions):
Again, brace expansion allows for individual numbers as well:
(note that in the example above, the brace expansion does not involve an arithmetic loop, but just generates names based on the strings provided).
bash, with the
extglob shell option enabled (
shopt -s extglob), the following will also work:
@(...) pattern will match any one of the included
The difference between globbing patterns as
@(...) and brace expansions, is that a brace expansion is generated on the command line and may not actually match any existing names in the current directory. A filename globbing pattern will match names, but the shell won't complain if not all possible name exist. If no matching name exists, the pattern will remain be unexpanded, unless also the
nullglob shell option is set, in which case the pattern is removed.
Here, only the file listing for
file1 will be shown.
ls would complain about not finding
In the following example, the first command will only touch existing names that matches the given pattern, while the second line will create files that does not already exist: