Introduction
Imagine you have a messy room with hundreds of scattered papers.
- Some are homework (
math_hw.txt,english_hw.txt). - Some are photos (
pic1.png,pic2.png). - Some are trash (
temp_1,temp_2).
If you want to move all the photos to a box, you don't pick them up one by one. You say: "Pick up anything that looks like a photo."
In Linux, we do this with Wildcards (also called Globbing). They are like the "Joker" cards in a deck—they can stand in for other characters.
This idea is powerful because it lets you work with patterns instead of individual names. On real systems, there may be dozens, hundreds, or thousands of matching files. Pattern-based selection is one of the reasons shell work scales so well.
In this lab, you will learn two powerful symbols:
- The Asterisk (
*): Represents anything (any length). - The Question Mark (
?): Represents one single character.
Select Multiple Files (*)
The asterisk * is the most famous wildcard. It means "Match any number of characters (including zero)."
Let's see what is in our messy folder:
ls
You filters files. Now, imagine you only want to list the text files (files ending in .txt).
Instead of typing ls notes.txt readme.txt report.txt, you simply type *.txt.
This translates to: "Find any file that ends with .txt."
ls *.txt
Output:
notes.txt readme.txt report.txt
The shell looked at *.txt, expanded it to match all the text files, and ignored image.png and others. You just filtered the list!
That sentence contains an important concept: the shell performs the pattern expansion before the ls command runs. In other words, ls often receives a finished list of filenames rather than the raw *.txt pattern. This explains why wildcards work across many different commands.
Move Files with *
Now let's do something useful. We have several data files: data_2025.csv, data_2024.csv, data_old.log.
We want to clean up. Let's move all files that start with data_ into a backup folder.
First, create the folder:
mkdir backup
Now, use the wildcard to move them all at once. The pattern data_* matches anything starting with data_.
mv data_* backup/
We just told Linux: "If it starts with data_, throw it in the backup box."
This is where wildcards become operationally useful. Instead of repeating a command for every matching file, you express a naming rule once and let the shell expand it for you.
Verify they are gone from the current directory:
ls
And check if they arrived safely:
ls backup
Success! You moved three files with one command.
Select Single Character (?)
The asterisk * is greedy—it grabs everything. Sometimes you need to be more careful.
The question mark ? wildcard represents exactly one character.
That makes ? more precise than *. It is useful when filenames follow a predictable format and you want to avoid accidentally matching longer names than intended.
We have files named temp_1, temp_2, and temp_a.
temp_*would matchtemp_1ANDtemp_very_long_name.temp_?matches only if there is exactly one character after the underscore.
Let's test our pattern before deleting (always a good habit!):
ls temp_?
Matches: temp_1, temp_2, temp_a.
Now that we are sure, let's delete them:
rm temp_?
Verify they are gone:
ls
This is very useful for matching files with specific naming structures.
The safety habit in this step is worth remembering: preview a pattern with a non-destructive command like ls before using it with rm or mv. Pattern matching is powerful, so it is wise to inspect before acting.
Summary
You have unlocked the power of pattern matching.
*(Asterisk): The "Match Everything" wildcard. Great for selecting all files of a type (*.png) or all files in a series (day_*).?(Question Mark): The "Single Character" wildcard. Great for precise matching (file_?.txt).
This concludes Module 2. You now know how to:
- Navigate the file tree (
pwd,cd,ls). - Create files and folders (
touch,mkdir). - Copy and move them (
cp,mv). - Delete them (
rm,rmdir). - Select them in batches (
*,?).
You are ready for Module 3, where we will open these files and actually read and edit the text inside them!


