Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • @Dennis Williamson, Any idea if this would still be true if a user has a different language set?
    – Zoredache
    Commented Mar 15, 2010 at 22:35
  • 10
    @Zoredache: It's actually specified by POSIX: opengroup.org/onlinepubs/007908775/xsh/glob.html "The pathnames are in sort order as defined by the current setting of the LC_COLLATE category, see the XBD specification, LC_COLLATE [opengroup.org/onlinepubs/007908775/xbd/…" and it's why you should do things like ls -l [[:lower:]] instead of ls -l [a-z]. Commented Mar 16, 2010 at 0:31
  • 1
    Note that the order is alphabetical so BigFilePiece.10 will come before BigFilePiece.2
    – Ken
    Commented Jul 24, 2014 at 13:14
  • @DennisWilliamson - Why two pairs of square brackets? One seems to work exactly the same to me. Commented Mar 14, 2018 at 21:08
  • 2
    @ArtOfWarfare: Try this: mkdir lctest; cd lctest; touch w; touch z; ls -l [:lower:]; echo =====; ls -l [[:lower:]]. The "z" file is only listed by the second ls because it's asking for lower case single-letter filenames. The first ls - the one without the outer square brackets - is asking for single-character file names from the list of characters ":", "l", "o", "w", "e", and "r". In both cases the outermost square brackets delimit a bracket expression which lists characters and classes. In the case of [[:lower:]], the inner square brackets, colons and word name a character class. ... Commented Mar 15, 2018 at 17:06