What are other wildcards available?

QuestionsQuestions8 SkillsProDec, 21 2025
0105

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].txt will show note_1.txt, note_2.txt, and note_3.txt, but ignore note_4.txt.

2. Negation [! ] or [^ ]

This matches any character not inside the brackets.

  • [!a]: Matches any character except 'a'.
  • Example: ls file[!1].txt will show file2.txt and file3.txt, but not file1.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 to cp file.txt file.txt.bak (a quick way to make a backup).
  • Example: rm {file1,note_5}.txt will 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

0 Comments

no data
Be the first to share your comment!