Glob (programming)
lastmod 2024-10-13created 2024-10-131 edits
Globs are a pattern matching technique long used on Linux operating systems to find multiple files at once.
Syntax types
-
? - Matches exactly one character, regardless of its type.
-
** - Matches zero or more subdirectories.
-
* - Matches any string, regardless of length.
-
{} - Matches several strings at once.
- For example,
**/*.{jpg,JPG}
-
[] - Matches file names based on a range of characters
- For example, to search for files whose names contain a lowercase vowel, you can use the pattern
**/*[aeiou]*.- Putting a
-between two characters uses every character between them for matching. For example, to search for files whose names start with an uppercase letter, you can use the pattern**/[A-Z]*. - Putting
!as the first character inside the[]brackets excludes the characters that follow from matching. For example, the pattern**/[!A-Z]*finds only files whose names don't start with an uppercase letter.
- Putting a
-
() - Using
()parentheses right after?or*lets you limit the choices to some extent during wildcard matching. - For example, the pattern
?(ab|cd)matches ab or cd, and also matches the empty string. - On the other hand, the pattern
*(ab|cd)can match many strings such as ab, abab, cd, cdcd, abcd, cdab, ababcdabcd.