Change ls datetime format - how?

Volker Wysk post at volker-wysk.de
Fri Feb 5 12:37:18 UTC 2021


Am Freitag, den 05.02.2021, 12:17 +0100 schrieb Bo Berglund:
> I am getting really frustrated by the way the command line on Ubuntu 18.04
> displays timestamps of files and directories...
> 
> When I use ls -l I get this:
> 
> $ ls -l
> total 100
> drwxr-xr-x 2 bosse bosse 4096 apr 26  2020 Backups
> drwxr-xr-x 2 bosse bosse 4096 feb  5 11:47 bin
> drwxr-xr-x 2 bosse bosse 4096 maj 26  2020 Desktop
> drwxr-xr-x 4 bosse bosse 4096 nov 30 08:43 dev
> 
> As you can see it is a complete mess regarding the timestamps.
> 
> I want the output to be like this instead:
> 
> $ ls -l
> total 100
> drwxr-xr-x 2 bosse bosse 4096 2020-04-26 11:05 Backups
> drwxr-xr-x 2 bosse bosse 4096 2021-02-05 11:47 bin
> drwxr-xr-x 2 bosse bosse 4096 2020-05-26 00:36 Desktop
> drwxr-xr-x 4 bosse bosse 4096 2020-11-30 08:43 dev
> 
> I also would like to be able to expand the time field to include the seconds:
> 
> $ ls -l
> total 100
> drwxr-xr-x 2 bosse bosse 4096 2020-04-26 11:05:52 Backups
> drwxr-xr-x 2 bosse bosse 4096 2021-02-05 11:47:04 bin
> drwxr-xr-x 2 bosse bosse 4096 2020-05-26 00:36:15 Desktop
> drwxr-xr-x 4 bosse bosse 4096 2020-11-30 08:43:17 dev
> 
> How can this be done?
> 
> I have tried to find a solution on-line but those are messing with locales and
> such, whereas I want my Ubuntu machines to always display the timestamps in ISO
> style as shown above.
> The following does not cut it either:
> 
> $ ls -l --time-style=iso
> total 100
> drwxr-xr-x 2 bosse bosse 4096 2020-04-26  Backups
> drwxr-xr-x 2 bosse bosse 4096 02-05 11:47 bin
> drwxr-xr-x 2 bosse bosse 4096 2020-05-26  Desktop
> drwxr-xr-x 4 bosse bosse 4096 11-30 08:43 dev
> 
> Here the year is missing on some entries while others do not display the time,
> generally a big mess!
> 
> And this is also bad since it seems to try to get time down to nanoseconds and
> includes time zone settings too:
> 
> $ ls -l --time-style=full-iso
> total 100
> drwxr-xr-x 2 bosse bosse 4096 2020-04-26 11:05:52.359305731 +0200 Backups
> drwxr-xr-x 2 bosse bosse 4096 2021-02-05 11:47:35.821484127 +0100 bin
> drwxr-xr-x 2 bosse bosse 4096 2020-05-26 00:36:15.372803793 +0200 Desktop
> drwxr-xr-x 4 bosse bosse 4096 2020-11-30 08:43:29.437636415 +0100 dev
> 
> 
> Please advice a setting I could but into .bashrc if needed to solve the problem.


alias ll="ls -l --time-style=full-iso |sed
's/^\(............................................\).................../\1/'
"

This needs to be on one line. The backslash in the first line is not to be
removed. 

This won't work with arguments to the ls command. You could write a script
or a bash function for that.

Bye
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20210205/8f0af8df/attachment.sig>


More information about the ubuntu-users mailing list