Languages
[Edit]
EN

Bash - format date & time from ls command

10 points
Created by:
Theodora-Battle
528

In this short article, we would like to show how to format date and time using ls command in Linux.

Quick solution:

ls -al --time-style=long-iso

Where:

  • --time-style=long-iso prints date & time in long-iso format (2021-06-24 10:53).
  • -al prints (or just a -l):
    • all files / directories (caused by -a),
    • in list format (caused by -l).

Example output:

root@server:/var# ls -al --time-style=long-iso
total 48
drwxr-xr-x 12 root root  4096 2021-05-29 17:28 .
drwxr-xr-x 18 root root  4096 2021-05-29 12:05 ..
drwxr-xr-x  2 root root  4096 2021-07-13 06:25 backups
drwxr-xr-x  8 root root  4096 2021-05-29 17:28 cache
drwxr-xr-x 24 root root  4096 2021-05-29 17:28 lib
drwxrwsr-x  2 root staff 4096 2020-05-02 18:39 local
lrwxrwxrwx  1 root root     9 2020-06-10 14:23 lock -> /run/lock
drwxr-xr-x 10 root root  4096 2021-07-13 00:00 log
drwxrwsr-x  2 root mail  4096 2020-06-10 14:23 mail
drwxr-xr-x  2 root root  4096 2020-06-10 14:23 opt
lrwxrwxrwx  1 root root     4 2020-06-10 14:23 run -> /run
drwxr-xr-x  4 root root  4096 2020-06-10 14:25 spool
drwxrwxrwt  5 root root  4096 2021-07-13 00:00 tmp
drwxr-xr-x  3 root root  4096 2021-05-29 17:28 www

Screenshot:

ls command date & time in long-iso format in Bash.
ls command date & time in long-iso format in Bash.

Alternative titles

  1. Bash - ls command with long-iso date & time format
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - format ls command date & time
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join