Wildcards provides special characters that makes Linux commands so powerful. Since the shell uses filenames so much, it provides special characters to help user rapidly specify groups of filenames.

Wildcards is also known as globbing which allow you to select filenames based on patterns of characters. Wildcards can be used with any command that accepts filenames as arguments The table below lists the wildcards and what they select:

WildcardMeaning
*Matches any characters
?Matches any single character
[characters]Matches any characters that is a member of the set characters
[!characters]Matches any characters that is not a member of the set characters
[[:class:]]Matches any characters that is a member of the specified class

Below is the commonly used character classes:

Characters ClassMeaning
[:alnum:]Matches any alphanumeric character
[:alpha:]Matches any alphabetic character
[:digit:]Matches any numeral
[:lower:]Matches any lowercase letter
[:upper:]Matches any uppercase letter

Examples

Using wildcards makes it possible to construct very sophisticated selection criteria for filenames. Here are some examples of patterns and what they match:

PatternMatches
*All files
g*Any file beginning with "g"
b*.txtAny file beginning with "g" and ending with ".txt"
Data???Any file beginning with "Data" followed by exactly three characters
[abc]*All files beginning with either an "a", a "b" or a "c"
BACKUP.[0-9][0-9][0-9]Any file beginning with "BACKUP." followed by exactly three numerals
[[:upper:]]*Any file beginning with an uppercase letter
[![:digit:]]*Any file not beginning with a numeral
*[[:lower:]123]Any file ending with a lowercase letter or the numerals “1”, “2”, or “3”

Characters Ranges

If you are coming from another Unix-like environment or have been reading some other books on this subject, you may have encountered the [A-Z] or the [a-z] character range notations. These are traditional Unix notations and worked in older versions of Linux as well. They can still work, but you have to be very careful with them because they will not produce the expected results unless properly configured.