Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Linux - Directory l...
 
Notifications
Clear all

[Solved] Linux - Directory listing with full date and time, or how to show Full Timestamps with the ls Command

1 Posts
1 Users
0 Reactions
7 Views
 Hans
(@hans)
Noble Member Admin
Joined: 13 years ago
Posts: 1066
Topic starter   [#1578]

Usually the Linux "ls -l" command only shows the date, which is often just fine but when running through large lists where the timestamp matters, its rather useless.

Eg:

$ ls -l

drwxr-xr-x 2 root root 16384 Aug  4 09:00 0
drwxr-xr-x 2 root root 20480 Aug  5 09:00 1
drwxr-xr-x 2 root root 20480 Aug  8 09:00 2
drwxr-xr-x 2 root root 16384 Aug 10 05:08 3
drwxr-xr-x 2 root root 12288 Aug 10 10:03 4
drwxr-xr-x 2 root root 16384 Aug  1 09:00 5

 

Timestamp with seconds: YYYY-MM-DD HH:MM:SS

To see the timestamp including seconds one needs to enter this command:

ls -l --time-style=+'%Y-%m-%d %H:%M:%S'

Not something I'd care for typing, but good if you need it only once in a blue moon, but results in just what we want:

$ ls -l --time-style=+'%Y-%m-%d %H:%M:%S'

total 332
drwxr-xr-x 2 root root 16384 2026-08-04 09:00:00 0
drwxr-xr-x 2 root root 20480 2026-08-05 09:00:17 1
drwxr-xr-x 2 root root 20480 2026-08-08 09:00:34 2
drwxr-xr-x 2 root root 16384 2026-08-10 05:08:03 3
drwxr-xr-x 2 root root 12288 2026-08-10 10:03:32 4
drwxr-xr-x 2 root root 16384 2026-08-01 09:00:05 5

To make this permanent, one can set the TIME_STYLE environment variable like so:

export TIME_STYLE=+'%Y-%m-%d %H:%M:%S'

From now on, "ls -l" will result in the full timestamp even with seconds (HH:MM:SS).

 

Timestamp without seconds: YYYY-MM-DD HH:MM

To see the timestamp including seconds one needs to enter this command:

ls -l --time-style=+'%Y-%m-%d %H:%M'

or:

ls -l --time-style=long-iso

If you do not care for the seconds, then you can try this, which results YYYY-MM-DD HH:MM (without the seconds):

export TIME_STYLE=long-iso

Which would result into something like this:

# ls -l

total 332
drwxr-xr-x 2 root root 16384 2026-08-04 09:00 0
drwxr-xr-x 2 root root 20480 2026-08-05 09:00 1
drwxr-xr-x 2 root root 20480 2026-08-08 09:00 2
drwxr-xr-x 2 root root 16384 2026-08-10 05:08 3
drwxr-xr-x 2 root root 12288 2026-08-10 10:03 4
drwxr-xr-x 2 root root 16384 2026-08-01 09:00 5

 

Note this is not so very relevant for macOS users, as Terminal/ls already shows the timestamp.
Hope this is useful to someone 😊 



   
ReplyQuote
Share: