ls -l date format ?

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
mark1mint

ls -l date format ?

Post by mark1mint »

I've seen that by default ls -l in Mint 13 lists the date field in this format

Code: Select all

Jul 16 18:20
which I find very convenient when using sort,therefore I'd like to replicate this setting in some other distros that I also use,only I haven't managed to understand where to look:in /etc/bash.bashrc I can't see anything regarding time or format,neither anything apparently related using printenv.

This has to be somewhere,or it is just the default behavior of ls in Ubuntu12/Mint13 ?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29511
Joined: Wed Jul 06, 2011 3:58 am

Re: ls -l date format ?

Post by xenopeek »

From the manpage of ls:

Code: Select all

       --time-style=STYLE
              with  -l, show times using style STYLE: full-iso, long-iso, iso,
              locale, +FORMAT.  FORMAT is interpreted like `date';  if  FORMAT
              is  FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files
              and FORMAT2 to recent files; if STYLE is prefixed with `posix-',
              STYLE takes effect only outside the POSIX locale
Doing a `ls -l --time-style=locale` gives me the default format, the one you desire (but it gives me that also without the --time-style=locale). The clue here being that the time style is taken from your locale. So if you have a different locale on another distro, it may display this differently. With the --time-style=+FORMAT, with FORMAT replaced by a format string as described in the date manpage, you can fully configure the time format. But I guess you have different locales. You can check your locale with the command `locale`.

Aside from /etc/bash.bashrc, also /etc/profile, /etc/profile.d and ~/.profile don't have any aliases for ls. Perhaps you added some? You can dump all your aliases with the command `alias`. Perhaps check that also on your other distro.
Image
mark1mint

Re: ls -l date format ?

Post by mark1mint »

Thank you very much,it could actually be a matter of different locale:I've now checked on Ubuntu 10.04,and there is this difference

Code: Select all

ubuntu                                                 mint
LANG=en_US.UTF-8                             LANG=en_US.UTF-8
LANGUAGE=en_US:en                            LANGUAGE=
maybe this is the reason why ls-l has a different time format ?

As for the aliases,I haven't any custom ones in Mint 13 neither Ubuntu,the latter has some more default aliases but none are related to ls - l time format.

Assuming that the slight difference above could be responsible for the different format,I wouldn't change the locale,I'd rather set a custom alias for the specific time format that I'm after:should I put it in /etc/bash.bashrc ?
User avatar
xenopeek
Level 25
Level 25
Posts: 29511
Joined: Wed Jul 06, 2011 3:58 am

Re: ls -l date format ?

Post by xenopeek »

I'm not sure that will make much a difference. Isn't the issue here that you are using a very old Ubuntu release, and probably just using a much different version of ls? Check version with:

Code: Select all

ls --version
From tests I have done the LANGUAGE set or unset doesn't make a difference. You can set the LANGUAGE temporarily with:

Code: Select all

export LANGUAGE=en_US:en
or unset it temporarily:

Code: Select all

unset LANGUAGE
Then run the locale command to confirm the change, and try your ls -l to see if it makes a difference. I doubt it. Close your terminal and open a new terminal, and the settings will be reset to their original values.

To change the setting of LANGUAGE permanently, I don't know for sure how to do that on such an old Ubuntu release. These days you would set it in /etc/default/locale.
Image
mark1mint

Re: ls -l date format ?

Post by mark1mint »

Yes,as you pointed out the ls version included in Ubuntu 10.04 is way older than the one in Mint 13 (kinda unsurprisingly,given that this is based on Ubuntu 12.04)-and also,as you suggested,the LANGUAGE=en_US:en variable doesn't do any difference,either when using export and then doing ls -l or using

Code: Select all

 env LANGUAGE=en_US:en ls-l 
If I really want to use that time format for ls -l,looks like I'll just have to set an alias,probably in .profile or .bashrc I guess.
Thanks for your help,BTW.
User avatar
xenopeek
Level 25
Level 25
Posts: 29511
Joined: Wed Jul 06, 2011 3:58 am

Re: ls -l date format ?

Post by xenopeek »

No problem. You can either set an alias in /etc/bash.bashrc to have it apply to all users, or indeed in your home folder in .bashrc to only apply it to you.
Image
Locked

Return to “Software & Applications”