EN
Bash - format date & time from ls command
10
points
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 justa
-l
):- all files / directories (caused by
-a
), - in list format (caused by
-l
).
- all files / directories (caused by
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: