In addition to the basic ones mentioned in your lab, here are some other powerful wildcards (often called "glob patterns") used in Linux:
1. Character Ranges [ - ]
Instead of listing every character, you can define a range.
[0-9]: Matches any single digit from 0 to 9.[a-z]: Matches any single lowercase letter.- Example:
ls note_[1-3].txtwill shownote_1.txt,note_2.txt, andnote_3.txt, but ignorenote_4.txt.
2. Negation [! ] or [^ ]
This matches any character not inside the brackets.
[!a]: Matches any character except 'a'.- Example:
ls file[!1].txtwill showfile2.txtandfile3.txt, but notfile1.txt.
3. Braces Expansion { , }
While not strictly a wildcard for matching existing files, it is used to generate patterns (like you did in Step 3).
- Example:
cp file.txt{,.bak}expands tocp file.txt file.txt.bak(a quick way to make a backup). - Example:
rm {file1,note_5}.txtwill remove exactly those two specific files.
4. Named Classes (POSIX)
These are special predefined sets:
[[:alnum:]]: Matches any alphanumeric character (letters and numbers).[[:alpha:]]: Matches any alphabetic character.[[:digit:]]: Matches any number.[[:upper:]]/[[:lower:]]: Matches uppercase or lowercase letters.
Quick Tip:
If you want to see how a wildcard expands without actually running a command like rm (delete), you can always test it with ls or echo. For example:
echo file?.txt
This will print out exactly what the shell thinks file?.txt represents before you do anything else