Title: Command Line Wildcards
Course: CIS 121: Linux/UNIX I: Fundamentals ~ For IGNITE Review > Section: Learning Modules

The command line will expand or process several special characters, called "wildcards", to match files in the referenced directory.

* (asterisk)

Sometimes called the "star", the asterisk will expand to match zero or more of any characters from the set of all characters. Examples:

- ls -d file*: List all items that start with "file".
- ls - d *file: List all items that end with "file".
- ls -d *file*: List all items that have "file" as part (or all) of the name.

? (question mark)

A question mark matches exactly one character. Examples:

- a? would match items starting with 'a' and followed by exactly one character ('ab', 'a5', 'aa', 'a.').
- ??b would match items with three character names and ending in 'b' ('bbb', 'aab', '12b', '1.b')
- f???* would match items that start with 'f' and have at least 4 characters ('file', 'funwithtacks', 'file14', 'foolonthehill')

[ ] (square brackets)

The square brackets are used to denote a single character from a set of characters. Examples:

- [abc] would match one character that is an 'a' or 'b' or 'c'.
- [0-9] would match one character that is a digit.
- [Michigan] would match one character that is a 'M' or 'i' or 'c' or 'h' or 'g' or 'a' or 'n', not the whole word 'Michigan'.
- file[1-3] would match 'file1' or 'file2' or 'file3'.

Wildcard "[ ]" Alphabetic Ranges

Whether a pattern '[a-z]' matches only lowercase letters depends on the setting of LC_COLLATE.

- export LC_COLLATE=C - Makes the search case-sensitive.
- export LC_COLLATE= - Makes the search not case-sensitive.