๐ Globbing (Wildcard Matching)
Globbing enables pattern matching in filenames and paths using wildcards like *, ?, and [...].
๐งญ Supported Patterns
| Pattern | Matches |
|---|---|
* |
Zero or more characters |
? |
Exactly one character |
[abc] |
Any one of listed characters |
[a-z] |
Any lowercase letter |
[^abc] |
Any character except those listed |
Examples:
1 2 3 | |
๐งช Practical Uses
Match hidden files:
1 | |
Exclude certain files:
1 | |
Combine with other commands:
1 2 3 | |
๐ง Differences Between Shells
Not all shells support advanced patterns equally:
| Feature | sh | bash | zsh | ksh |
|---|---|---|---|---|
| Basic globbing | โ | โ | โ | โ |
| Extended globs | โ | โ | โ | โ |
| Recursive glob | โ | โ | โ | โ |
Enable extended globbing in bash:
1 | |
๐งพ Summary
- Globbing simplifies batch processing of files.
- Be aware of shell-specific limitations.
- Always quote variables that might contain glob patterns.
- Use carefully to avoid unintended matches.
๐ Continue to: Scripts and Shebang