Pattern matching using [ ] shell metacharacters

Metacharacters offer another type of wildcard notation by enclosing the desired characters within [ ]. It is like using the ?, but it allows you to choose specific characters to be matched.

The [ ] also allow you to specify a range of values using the hyphen (-). To specify all the letters in the alphabet, use [[:alpha:]]. To specify all the lowercase letters in the alphabet, use [[:lower:]].
See the following examples:
  • To refer to only the files that end in 1 or 2, use:
    *file[12]
    The files selected would be: afile1, afile2, file1, and file2.
  • To refer to only the files that start with any number, use:
    [0123456789]* or [0-9]*
    The files selected would be: 1test and 2test.
  • To refer to only the files that do not begin with an a, use:
    [!a]*
    The files selected would be: 1test, 2test, bfile1, file, file1, file10, file2, and file3.