In one of my systems, when I run ls [:lower:]*, it will list all files that start with a lowercase letter.

In another one, it will give an error:

ls: cannot access [:lower:]*: No such file or directory

There are files that start with a lowercase in the working directory.

Running ls [[:lower:]]* instead, will work on both systems. I'd like to understand why ls [:lower:]* does not work in the second system and what is the proper way to use character classes.

Both are running Bash, but I would like an answer that I can apply to other shells as well.


Your first example didn't do what you thought it did; it instead listed all the filenames that started with any one of the following characters:

  • :
  • e
  • l
  • o
  • r
  • w

(those are the letters of lower, re-sorted). To use a character class, you must already be within the square brackets and then use [:lower:], as in your second example.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.