Perform Basic File Management – Part 1
Simple and Advanced Wildcard Specifications in Commands
In this lesson, you’ll master wildcard (glob) patterns in Linux to search, copy, move, or delete files efficiently. Wildcards are symbols that stand for one or more characters in file names or paths. We’ll cover three primary types:- Asterisk (
*) - Question mark (
?) - Bracketed expressions (
[ ])
![The image explains types of wildcards: asterisk (*) for zero or more occurrences, question mark (?) for a single occurrence, and brackets ([]) for specific character occurrences, with an example of [0-9] matching all digits.](https://kodekloud.com/kk-media/image/upload/v1752881396/notes-assets/images/Linux-Professional-Institute-LPIC-1-Exam-101-Perform-Basic-File-Management-Part-1-Simple-and-advanced-wildcard-specifications-in-commands/wildcards-asterisk-question-brackets-example.jpg)
Wildcard Reference Table
| Wildcard | Matches | Example Pattern | Matches |
|---|---|---|---|
* | Zero or more characters | *.log | kern.log, sys.log, apperror.log |
? | Exactly one character | ?.conf | a.conf, b.conf, not ab.conf |
[ ] | Any one character in a set or range | [0-9].txt | 1.txt, 5.txt, 9.txt |
1. Asterisk (*)
The asterisk is the most flexible wildcard—it matches any string of characters (even an empty string).
In interactive shells, wrap
* patterns in quotes (e.g., "*.png") to prevent premature expansion by your shell.2. Question Mark (?)
The question mark matches exactly one character. It’s ideal for pinpointing files that differ by a single letter or digit.
3. Bracketed Characters ([ ])
Square brackets let you match one character from a specified set or range.
4. Combining Wildcards
For advanced file matching, mix wildcards in a single pattern:Be cautious when using wildcards with destructive commands like
rm. Always double-check your pattern with ls before deletion.