Change ls datetime format - how?

Bo Berglund bo.berglund at gmail.com
Fri Feb 5 11:17:27 UTC 2021


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.


-- 
Bo Berglund
Developer in Sweden





More information about the ubuntu-users mailing list