Globs: Using wildcards to match files and directories in Linux
published on Tue Mar 17 2020Globbing refers to using wildcards and a system of identifiers to expand search strings into the list of pathnames matching the search string pattern. This can give us superpowers when working with multiple files.

This is useful for us whenever we are working with multiple files and need to move, copy, delete them. We also use these patterns in other applications when specifying which files to include or which files to ignore. For example, we use these patterns in a .gitignore
file to tell Git which files to ignore
Wildcards
*
- matches any character?
- matches any single character[...]
- matches any character in the square brackets[!...]
- matches any character not in the square brackets[[:class:]]
- matches any character that is a member of the specified class
Note - We can use -
inside the square brackets to denote ranges like we do for regular expressions
Some common classes are listed below
Common Classes
[:alnum:]
- matches any alphanumeric character[:alpha:]
- matches any alphabetic character[:digit:]
- matches any numeral[:lower:]
- matches any lowercase letter[:upper:]
- matches any uppercase letter
Examples
*
- all files**
- all files including ones inside subfoldersdir1/g*
- any file beginning with a g inside dir1dir2/b*.txt
- any file inside dir2 beginning with b followed by any characters and ending with .txtData???
- any file beginning with Data followed by exactly 3 charactersdir1/[abc]*
- any file inside dir1 beginning with a, b or cBACKUP.[0-9][0-9][0-9]
- any file beginning with BACKUP. followed by exactly three numerals[[:upper:]]*
- any file beginning with an uppercase letter[![:digit:]]*
- any file not beginning with a numeral*[[:lower:]123]
- any file ending with a lowercase letter or the numerals 1, 2 or 3