The Star Wildcard
Part of the Fundamentals section of Coddy's Terminal journey — lesson 25 of 82.
A wildcard is a special character that acts as a placeholder to match one or more characters in filenames. Wildcards let you work with multiple files at once without typing every name.
The star wildcard * matches any number of characters (including zero). It is the most powerful and commonly used wildcard.
For example, to list all files ending in .txt:
ls *.txtThis matches any filename that ends with .txt, no matter how long the name is.
More examples:
Match all files starting with photo:
ls photo*Match all files containing report anywhere in the name:
ls *report*Match all files of any name or extension:
ls *You can use * with any command, not just ls. For example, copy all .jpg files into a folder:
cp *.jpg photos/Or delete all .log files at once:
rm *.logTip: Always run
lswith your wildcard pattern first before using it withrmormv— this way you can see exactly which files will be affected before making any changes.
Challenge
BeginnerUse the * wildcard to list only the .jpg files in the current directory.
Hint: Combine
lswith the*wildcard and the.jpgextension to filter only image files.
Cheat sheet
A wildcard is a special character that matches one or more characters in filenames, allowing you to work with multiple files at once.
The star wildcard * matches any number of characters (including zero).
Examples:
List all files ending with .txt:
ls *.txtList all files starting with photo:
ls photo*List all files containing report anywhere in the name:
ls *report*List all files:
ls *Copy all .jpg files into a folder:
cp *.jpg photos/Delete all .log files:
rm *.logTip: Always run
lswith your wildcard pattern first before using it withrmormvto see which files will be affected.
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