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