"ls" command and ISO date format
By default, ls
linux command prints dates in Mmm dd HH:MM
or in Mmm dd YYYY
format for recently and non-recently changed files, respectively.
Sometimes it is more comfortable to see the dates and times in ISO 8601 format like YYYY-mm-dd HH:MM
or YYYY-mm-dd HH:MM:SS
.
Prepare Test Data
touch -d '2016-01-01 13:56:11' file-1.log
touch -d '2017-08-17 18:51:57' file-2.log
touch -d '2017-08-18 07:00:04' file-3.log
touch -d '2017-08-18 12:10:54' file-4.log
touch -d '2017-08-18 14:02:33' file-5.log
Default Date Format
> ls -ltr file-*
-rw-r--r-- 1 user users 0 Jan 1 2016 file-1.log
-rw-r--r-- 1 user users 0 Aug 17 18:51 file-2.log
-rw-r--r-- 1 user users 0 Aug 18 07:00 file-3.log
-rw-r--r-- 1 user users 0 Aug 18 12:10 file-4.log
-rw-r--r-- 1 user users 0 Aug 18 14:02 file-5.log
Options:
l
- long list formattr
- sort by last modified date in ascending order
ISO Long Date Format
> ls -ltr --time-style=long-iso file-*
-rw-r--r-- 1 user users 0 2016-01-01 13:56 file-1.log
-rw-r--r-- 1 user users 0 2017-08-17 18:51 file-2.log
-rw-r--r-- 1 user users 0 2017-08-18 07:00 file-3.log
-rw-r--r-- 1 user users 0 2017-08-18 12:10 file-4.log
-rw-r--r-- 1 user users 0 2017-08-18 14:02 file-5.log
Options:
l
- long list formattr
- sort by last modified date in ascending order--time-style=long-iso
- with this option dates in results are shown in ISOYYYY-mm-dd HH:MM
format, with minutes precision
ISO Full Date Format
> ls -ltr --time-style=full-iso file-*
-rw-r--r-- 1 user users 0 2016-01-01 13:56:11.000000000 +0300 file-1.log
-rw-r--r-- 1 user users 0 2017-08-17 18:51:57.000000000 +0300 file-2.log
-rw-r--r-- 1 user users 0 2017-08-18 07:00:04.000000000 +0300 file-3.log
-rw-r--r-- 1 user users 0 2017-08-18 12:10:54.000000000 +0300 file-4.log
-rw-r--r-- 1 user users 0 2017-08-18 14:02:33.000000000 +0300 file-5.log
Options:
l
- long list formattr
- sort by last modified date in ascending order--time-style=full-iso
- with this option dates in results are shown in ISOYYYY-mm-dd HH:MM:SS.NNNNNNNNN+|-HHMM.
format, with nanoseconds and time zone
Custom Date Format
> ls -ltr --time-style="+%Y-%m-%d %H:%M:%S" file-*
-rw-r--r-- 1 user users 0 2016-01-01 13:56:11 file-1.log
-rw-r--r-- 1 user users 0 2017-08-17 18:51:57 file-2.log
-rw-r--r-- 1 user users 0 2017-08-18 07:00:04 file-3.log
-rw-r--r-- 1 user users 0 2017-08-18 12:10:54 file-4.log
-rw-r--r-- 1 user users 0 2017-08-18 14:02:33 file-5.log
Options:
l
- long list formattr
- sort by last modified date in ascending order--time-style="+%Y-%m-%d %H:%M:%S"
- with this option dates in results are shown inYYYY-mm-dd HH:MM:SS
format, with seconds precision