Yes, absolutely! You can combine * and ? (as well as square brackets []) in a single pattern to create very specific searches.
When you combine them, the shell processes each metacharacter according to its own rule:
?will match exactly one character at its specific position.*will match any number of characters (including zero) for the rest of that part of the pattern.
Example Scenario
Imagine you have the following files:
test1.txttest2.txttest10.txttaskA.txttaskAB.txt
If you use the pattern t?st*.txt:
t: Matches the literal letter 't'.?: Matches exactly one character (like 'e' intestor 'a' intask).st: Matches the literal letters 'st'.*: Matches any characters remaining before the extension (like '1', '2', or '10')..txt: Matches the literal extension.
Results of ls t?st*.txt:
- It would match
test1.txt,test2.txt, andtest10.txt. - It would not match
taskA.txtbecause the pattern expectsstafter the second character.
Try it in your VM!
Since you just learned about touch, you can test this combination yourself:
# Create some test files
touch match1.ox match22.ox matchABC.ox mismatch.ox
# Try a combined pattern
# This looks for "match", then exactly ONE character, then anything else ending in .ox
ls match?*.ox
In this case, match?*.ox would find match1.ox, match22.ox, and matchABC.ox because they all have at least one character after the word "match".
Do you have a specific naming pattern in mind that you're trying to match?