0

I am using ls on MacOS 11.6.1. In the output, the Upper cases are displayed before the lower case. For example, I get the following output:

$ ls

Blabla.txt GAGAS.txt asdf.txt blabla.txt

and would like to have instead:

$ ls

asdf.txt blabla.txt Blabla.txt GAGAS.txt

Is this the normal default output of ls? How can I have the output number 2?

ecjb
  • 403

1 Answers1

1

ls is required by POSIX to sort the file names in its output according to the collating sequence in the current locale.

If your system has no locale where the sort order ignores case at least in the first pass of comparing strings, you could try piping to sort -f:

ls -q | sort -f

(with the -q option to guarantee file names are displayed on one line by replacing control characters in them including newline with ? (beware that may affect the order).

Or with the zsh shell, use something like:

lc() REPLY=$REPLY:l
print -rC1 -- *(o+lc)

Instead of ls. That is define a lc helper function that changes the value of $REPLY to lower case, and use that as an ordering function for the glob expansion (not necessarily strictly equivalent to a case-insensitive comparison, but should be close enough especially for ASCII only text).