Wildcards and globbing are used to match:
- File names
- Directory names
- Patterns
They help users work with multiple files quickly.
What is Globbing?
Globbing is the process where the shell expands wildcard patterns into matching filenames.
Example:
ls *.txt
The shell automatically replaces:
- .txt
with all matching .txt files.
Common Wildcards
| Wildcard | Meaning |
|---|---|
| * | Match zero or more characters |
| ? | Match single character |
| [] | Match character range/set |
| {} | Match multiple patterns |
| ~ | Home directory shortcut |
*1. Asterisk **
Meaning
Matches:
zero or more characters
Examples
Match All Files
ls *
Match Text Files
ls *.txt
Matches:
notes.txt
app.txt
Match Log Files
ls *.log
Real-World Usage
Delete Old Logs
rm *.log
Copy All YAML Files
cp *.yaml /backup/
Common in Kubernetes management.
2. Question Mark ?
Meaning
Matches:
exactly one character
Example
ls file?.txt
Matches:
file1.txt
fileA.txt
Does NOT match:
file10.txt
Real-World Usage
Match Numbered Files
ls backup?.tar
3. Square Brackets []
Meaning
Matches specific characters or ranges.
Examples
Match Specific Characters
ls file[123].txt
Matches:
file1.txt
file2.txt
file3.txt
Match Character Range
ls file[a-z].txt
Match Numbers
ls log[0-9].txt
Real-World Usage
Process Multiple Server Configs
cat server[1-5].conf
4. Curly Braces {}
Meaning
Used for pattern expansion.
Example
mkdir {dev,test,prod}
Creates:
dev/
test/
prod/
Multiple Extensions
ls *.{txt,log}
Matches:
app.txt
error.log
Real-World Usage
Create Deployment Structure
mkdir -p app/{logs,config,data}
Creates:
app/logs
app/config
app/data
Very common in DevOps setups.
5. Tilde ~
Meaning
Represents:
home directory
Example
cd ~
Moves to:
/home/user
View Hidden Files with Wildcards
Hidden files start with:
.
Example:
ls .*
Combining Wildcards
Example
ls backup*.tar.gz
Matches:
backup1.tar.gz
backup_final.tar.gz
Recursive File Operations
Find All YAML Files
find . -name "*.yaml"
Very common in Kubernetes projects.
Practical DevOps Examples
Kubernetes YAML Files
kubectl apply -f *.yaml
Applies all YAML manifests.
Backup Logs
cp /var/log/*.log /backup/
Remove Temporary Files
rm temp*
Deploy Multiple Configs
scp config*.json server:/opt/config/
Top comments (0)