Przejdลบ do treล›ci

๐ŸŒ 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
ls *.txt           # All .txt files
ls file?.log       # file1.log, fileA.log
ls [a-c]*.sh       # Files starting with a, b, or c ending in .sh


๐Ÿงช Practical Uses

Match hidden files:

1
ls .*              # Includes .bashrc, .gitconfig, ..

Exclude certain files:

1
ls !(temp).txt     # Requires extglob enabled in bash

Combine with other commands:

1
2
3
rm *.tmp
cp backup/*.conf .
find . -name "*.bak" -delete


๐Ÿง  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
shopt -s extglob


๐Ÿงพ 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