Skip to main content
Glob patterns are a powerful tool for matching filenames. They are commonly used in Unix and Linux shells, as well as in other programming languages and tools. Glob patterns are made up of characters that have special meanings. For example, the asterisk (*) matches any sequence of characters, and the question mark (?) matches any single character.

Syntax

The syntax for glob patterns is as follows: pattern ::=char* | char* "?" | char* "" | char "?" | char* "" | "{" char "," char* "}" | "{" char* "," char* "," char* "}" | "[" char* "-" char* "]" | "[" char* "-" char* "]" | "[" char* "]" | "[" char* "]" Where: char is any character except \*, ?, [, ], {, }, ", or '. Examples The following table shows some examples of glob patterns and their meanings: Advanced Features Glob patterns also support some advanced features, such as recursive matching and negative matching. Recursive matching: The ** pattern matches any sequence of directories, including zero or more directories. For example, the pattern **/*.txt matches any file with a .txt extension, regardless of how many directories it is nested in. Negative matching: The ! character can be used to negate a pattern. For example, the pattern !*.txt matches any file that does not have a .txt extension.