How does `[a-z]` work?

QuestionsQuestions8 SkillsProDec, 11 2025
0138

That's a great question!

The wildcard [a-z] works similarly to [abc], but instead of matching specific characters, it matches any single character within the specified range.

So, [a-z] will match any single lowercase letter from a to z.

Here's an example:

If you have files like:

  • letter_a.txt
  • letter_b.txt
  • letter_m.txt
  • letter_z.txt
  • letter_1.txt

The command ls letter_[a-z].txt would list:

  • letter_a.txt
  • letter_b.txt
  • letter_m.txt
  • letter_z.txt

It would not list letter_1.txt because 1 is not a lowercase letter.

You can also use other ranges, like:

  • [A-Z] for any single uppercase letter.
  • [0-9] for any single digit.
  • [a-zA-Z0-9] for any single alphanumeric character.

This is a very powerful way to select files based on patterns in their names!

Does that make sense? Let me know if you'd like to try an example!

0 Comments

no data
Be the first to share your comment!