[Techtalk] what the heck is it with locale and ls -l -- recap with correct outputs

Wim De Smet kromagg at gmail.com
Fri Feb 24 09:32:23 UTC 2012


Hi,

Here's a discussion on an old patch (2009) for coreutils:
http://lists.gnu.org/archive/html/bug-coreutils/2009-09/msg00388.html

To summarize: it seems that if ls can't find a translation in the
current locale for the date-time format, it falls back to long-iso.
Back when the bug was reported (2009), apparently the desired
behaviour was the C-style formatting you're seeing in your Fedora
output.

I think what happened is that in newer versions of libc, the default
simply changed. See the debian reference on this point:
http://www.debian.org/doc/manuals/debian-reference/ch09.en.html#_customized_display_of_time_and_date

Though I'm not sure it just depends on libc, I think coreutils might
be shipping their own .mo files. Anyway, always fun (ahem) to dig into
(the average linux distro is held together with a lot of duct tape).
The morale of the story: locale formatting is for human beings only,
always force some form of ISO formatting if you're using ls output in
a script. The same goes for date, btw.

And to get back to the discussion of what is "best", I have to say
there's a certain benefit to the POSIX style formatting, making it
easier to read at a glance. It's the same reason you'll see stuff like
"2 hours ago" instead of simply the time on sites like twitter or
blogs. And now I'm thinking how you can get ls to do something
similar. :-)

regards,
Wim

On Thu, Feb 23, 2012 at 7:09 PM, Carla Schroder <carla at bratgrrl.com> wrote:
> Heh, sorry for mail-bombing the list-- I keep getting mixed up and posting
> mistakes. So here is a recap for the benefit of anyone following alone, with
> correct outputs:
>
> Two distros: Mint 12 and Fedora 16
>
> Mint 12 has coreutils 8.5
> Fedora 16 has coreutils 8.2
>
> Both have the same locale: en_US.UTF-8
>
> carla at mint ~ $ locale
> LANG=en_US.UTF-8
> LANGUAGE=
> LC_CTYPE="en_US.UTF-8"
> LC_NUMERIC="en_US.UTF-8"
> LC_TIME="en_US.UTF-8"
> LC_COLLATE="en_US.UTF-8"
> LC_MONETARY="en_US.UTF-8"
> LC_MESSAGES="en_US.UTF-8"
> LC_PAPER="en_US.UTF-8"
> LC_NAME="en_US.UTF-8"
> LC_ADDRESS="en_US.UTF-8"
> LC_TELEPHONE="en_US.UTF-8"
> LC_MEASUREMENT="en_US.UTF-8"
> LC_IDENTIFICATION="en_US.UTF-8"
> LC_ALL=
>
> [carla at fedora ~]$ locale
> LANG=en_US.UTF-8
> LC_CTYPE="en_US.UTF-8"
> LC_NUMERIC="en_US.UTF-8"
> LC_TIME="en_US.UTF-8"
> LC_COLLATE="en_US.UTF-8"
> LC_MONETARY="en_US.UTF-8"
> LC_MESSAGES="en_US.UTF-8"
> LC_PAPER="en_US.UTF-8"
> LC_NAME="en_US.UTF-8"
> LC_ADDRESS="en_US.UTF-8"
> LC_TELEPHONE="en_US.UTF-8"
> LC_MEASUREMENT="en_US.UTF-8"
> LC_IDENTIFICATION="en_US.UTF-8"
> LC_ALL=
>
> Both support a full range of locales, as confirmed with local -a, including
> en_US.UTF-8
>
> There are no environmental variables or aliases that I can find that control
> date formatting for ls -l. Yet Fedora displays dates as LC_TIME="C":
>
> [carla at fedora-verne etc]$ ls -l
> drwxr-xr-x.  3 root root     4096 Nov  2 19:30 abrt
> -rw-r--r--.  1 root root       46 Jan 11 11:29 adjtime
> -rw-r--r--.  1 root root     1518 Aug 16  2011 aliases
> -rw-r-----.  1 root smmsp   12288 Nov  2 19:30 aliases.db
>
> While Mint displays correctly in long-iso:
>
> carla at studio /etc $ ls -l
> drwxr-xr-x  3 root  root      4096 2012-02-17 19:02 acpi
> -rw-r--r--  1 root  root      2981 2011-10-12 08:08 adduser.conf
> -rw-r--r--  1 root  root        10 2012-02-17 17:16 adjtime
> drwxr-xr-x  2 root  root      4096 2011-10-12 08:11 akonadi
>
> There are workarounds such as setting environmental variables or aliasing ls -
> l.  These are simple to implement and they work.
>
> The remaining puzzlement is why? What controls the defaults? I don't want to
> make this my life's work or drive my fellow Techtalkers crazy, but it would be
> nice to know. Someone somewheres suggested that it's a coreutils issue, that
> the default used to be TIME_STYLE=long-iso, and then with version 8.5 it
> changed to TIME_STYLE=locale. Which still doesn't explain Fedora.
>
> best,
> Carla


More information about the Techtalk mailing list