Sorting “Dot” Files

As I got Cent OS 7.4 running, a bit strange thing happened. When I ran usual ll (alias to ls -lA), I got a slightly unexpected result:

# ll
drwxrwx--- 4 apache apache 4096 Dec 24 06:50 download
-rw-rw---- 1 apache apache 5430 Dec 23 08:06 favicon.ico
-rw-rw---- 1 apache apache 12300 Dec 26 02:25 .htaccess
-rw-rw---- 1 apache apache 460 Dec 23 08:06 index.php
-rw-rw---- 1 apache apache 117 Dec 23 20:39 robots.txt
drwxrwx--- 2 apache apache 4096 Dec 26 01:44 .well-known
drwxrwx--- 5 apache apache 4096 Dec 23 17:32 wordpress

Can you spot the issue?

Yep, Cent OS got a bit (too) smart so sorting ignores the starting dot and gets those files too in the alphabetic order. Those used to dot files on the top - though luck.

Well, it's possible to "correct" this behavior using the slightly different alias in .bashrc:

alias ll='LC_COLLATE=C ls -lA'

This gives a (properly) sorted output:

# ll
-rw-rw---- 1 apache apache 12300 Dec 26 02:25 .htaccess
drwxrwx--- 2 apache apache 4096 Dec 26 01:44 .well-known
drwxrwx--- 4 apache apache 4096 Dec 24 06:50 download
-rw-rw---- 1 apache apache 5430 Dec 23 08:06 favicon.ico
-rw-rw---- 1 apache apache 460 Dec 23 08:06 index.php
-rw-rw---- 1 apache apache 117 Dec 23 20:39 robots.txt
drwxrwx--- 5 apache apache 4096 Dec 23 17:32 wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *