What does `[a-z]` match?

QuestionsQuestions8 SkillsProDec, 22 2025
0107

Great question! The wildcard [a-z] follows the same logic as [abc], but it uses a hyphen (-) to represent a range of characters.

Instead of typing every single letter, [a-z] matches any single lowercase letter from 'a' to 'z'.

How it works:

  • Matches: Any one lowercase character (a, b, c, ... x, y, z).
  • Does NOT match: Numbers, uppercase letters (usually, depending on your system's settings), or special symbols.

Practical Examples:

If you have a folder with these files:

  • note_a.txt
  • note_b.txt
  • note_1.txt

The command ls note_[a-z].txt would only show note_a.txt and note_b.txt. It would ignore note_1.txt because 1 is not a letter.

Other common ranges:

  • [A-Z]: Matches any single uppercase letter.
  • [0-9]: Matches any single digit from 0 to 9.
    • Try this in your current lab! Since you created file1.txt through file3.txt, you can run:
      ls file[0-9].txt

You can even combine them! For example, [a-zA-Z] matches any letter regardless of case.

Happy experimenting, you're doing great with these wildcards

0 Comments

no data
Be the first to share your comment!