File globbing in Linux
Zhenguo Zhang
Bioinformatics scientist dedicated to healthcare innovation, fueled by diverse skills and a commitment to lifelong learning
One can use the following patterns to match files:
Pattern | Description
* | Match zero or more characters
? | Match any single character
[...] | Match any of the characters in a set
{abc,def} | Match any strings in a set
?(patterns) | Match zero or one occurrences of the patterns (extglob)
*(patterns) | Match zero or more occurrences of the patterns (extglob)
+(patterns) | Match one or more occurrences of the patterns (extglob)
@(patterns) | Match one occurrence of the patterns (extglob)
!(patterns) | Match anything that doesn't match one of the patterns (extglob)
For example, one can use the following to match any files ending with jpg or gif
ls *.jpg *.gif
ls *.?(jpg|gif)
ls *.{jpg,gif}
Note the pattern modifiers for extended globbing are put ahead of patterns, different from the regular expression in other language such as Perl and Python.
One can find more examples at https://www.linuxjournal.com/content/pattern-matching-bash