glob (programming)
In computer programming, glob (/ɡlɒb/) patterns specify sets of filenames with wildcard characters. For example, the Unix Bash shell command mv *.txt textfiles/
moves all files with names ending in .txt
from the current directory to the directory textfiles
. Here, *
is a wildcard and *.txt
is a glob pattern. The wildcard *
stands for "any string of any length including empty, but excluding the path separator characters (/
in unix and \
in windows)".
The other common wildcard is the question mark (?
), which stands for one character. For example, mv ?.txt shorttextfiles/
will move all files named with a single character followed by .txt
from the current directory to directory shorttextfiles
, while ??.txt
would match all files whose name consists of 2 characters followed by .txt
.
In addition to matching filenames, globs are also used widely for matching arbitrary strings (wildcard matching). In this capacity a common interface is fnmatch
.