Globbing Patterns
Globbing is sometimes used to refer to pattern matching based on wildcard characters. The noun “glob” is used to refer to a particular pattern, e.g. “use the glob
*.log
to match all those log files”. Its notation is simpler than regular expressions, and without their expressive power.
Wildcard matching
?
- A
?
(not between brackets) matches any single character. *
- A
*
(not between brackets) matches any string, including the empty string. #
- A line starts with
#
serves as a comment. !
- Prefix
!
negates the pattern. {}
,{!}
{a,b,c}
matches any one of a, b or c.{!glob}
matches anything that does not matchglob
.[]
,[^]
[abc]
matches any character in the set a, b or c.[^abc]
matches any character not in the set a, b or c.[a-z]
matches any character in the range a to z, inclusive (A leading or trailing dash will be interpreted literally)./
- Pattern ends with a
/
matches pathname. - For example,
Documentation/*.html
matchesDocumentation/git.html
but notDocumentation/ppc/ppc.html
ortools/perf/Documentation/perf.html
. **
- A leading
**/
matches in all directories. E.g.**/foo/bar
matches file or directorybar
anywhere that is directly under directoryfoo
. - A trailing
/**
matches everything inside. E.g.abc/**
matches all files inside directory “abc”, relative to the location /**/
matches zero or more directories. E.g.a/**/b
matchesa/b
,a/x/b
,a/x/y/b
and so on.- Other consecutive asterisks are considered invalid.
References
man 5 gitignore
- Grunt Globbing Patterns