How to ignore files
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:
Pattern | Meaning |
---|---|
\* | Matches any sequence of characters. |
? | Matches any single character. |
\*.txt | Matches any file with a .txt extension. |
\*.c? | Matches any file with a .c extension and a single character following the .c. |
?\*.txt | Matches any file with a .txt extension and a single character preceding the .txt. |
[a-z]\*.txt | Matches any file with a .txt extension and a filename that starts with a lowercase letter. |
[0-9]\*.txt | Matches any file with a .txt extension and a filename that starts with a number. |
[!0-9]\*.txt | Matches any file with a .txt extension and a filename that does not start with a number. |
{a,b}\*.txt | Matches any file with a .txt extension and a filename that starts with either a or b. |
{a,b,c}\*.txt | Matches any file with a .txt extension and a filename that starts with a, b, or c. |
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.