The Question Mark Wildcard
Part of the Fundamentals section of Coddy's Terminal journey — lesson 26 of 82.
The question mark wildcard ? matches exactly one character. Unlike * which matches any number of characters, ? is more precise — each ? represents a single character position.
For example, if you have these files:
file1.txt
file2.txt
file3.txt
file10.txt
notes.txtUsing ? to match files with exactly one character after file:
ls file?.txtOutput:
file1.txt
file2.txt
file3.txtNotice that file10.txt is not matched because 10 is two characters, not one.
Using multiple question marks:
Each ? matches exactly one character, so you can chain them:
ls file??.txt # matches file10.txt, file23.txt etc.Mixing with other characters:
ls ???.txt # matches any .txt file with exactly 3-character name
ls img_?.jpg # matches img_1.jpg, img_2.jpg but NOT img_10.jpgWhen to use ? vs *:
- Use
?when you know exactly how many characters vary - Use
*when the number of varying characters is unknown
Challenge
BeginnerUse the ? wildcard to list only the files that match file?.txt — files named file followed by exactly one character and ending with .txt.
Hint:
file10.txtshould not appear in your results because10is two characters. The?wildcard matches only one character at a time.
Cheat sheet
The question mark wildcard ? matches exactly one character. Unlike * which matches any number of characters, ? is more precise — each ? represents a single character position.
Example matching files with exactly one character after file:
ls file?.txtUsing multiple question marks:
Chain multiple ? to match multiple characters:
ls file??.txt # matches file10.txt, file23.txt etc.Mixing with other characters:
ls ???.txt # matches any .txt file with exactly 3-character name
ls img_?.jpg # matches img_1.jpg, img_2.jpg but NOT img_10.jpgWhen to use ? vs *:
- Use
?when you know exactly how many characters vary - Use
*when the number of varying characters is unknown
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline