22. Bash Shell - Pattern Matching (Globbing Wildcards)
Contents
With the matching patterns, we can easily and efficiently find the files or directories we need.
Preparation
Let’s prepare some test files first before we start:
|
|
Special Pattern Characters
Match any string
We can use the * character to match any string.
Match any file that starts with file
|
|
Match any file that ends with .txt
|
|
Match any character
We can use the ? character to match any character.
Match any file with a 1-character filename
|
|
Match any file with a 4-character extension
|
|
Match any one of enclosed characters
We can use the [] range expression to match any one of enclosed characters.
Match any file that starts with 1, 2 or f
|
|
Match any file that starts with 1, 2 or 3
|
|
Match any file that starts without 1, 2 or 3
|
|
References 3.5.8.1 Pattern Matching
Author Dong Chen
LastMod Sat Feb 23 2019