LS Command – Why Does ‘ls -all’ Show Time for Some Files but Only Year for Others?

ls

If you issue ls -all command some files or directories have the year and some have the time? Why do some show the year while others show the time? Is the time representative of the time the file was created?

enter image description here

Best Answer

By default, file timestamps are listed in abbreviated form, using a date like ‘Mar 30 2002’ for non-recent timestamps, and a date-without-year and time like ‘Mar 30 23:45’ for recent timestamps. This format can change depending on the current locale as detailed below.

A timestamp is considered to be recent if it is less than six months old, and is not dated in the future. If a timestamp dated today is not listed in recent form, the timestamp is in the future, which means you probably have clock skew problems which may break programs like make that rely on file timestamps.

Source: http://www.gnu.org/software/coreutils/manual/coreutils.html#Formatting-file-timestamps

To illustrate:

$ for i in {1..7}; do touch -d "$i months ago" file$i; done
$ ls -l
total 0
-rw-r--r-- 1 terdon terdon 0 Sep 21 02:38 file1
-rw-r--r-- 1 terdon terdon 0 Aug 21 02:38 file2
-rw-r--r-- 1 terdon terdon 0 Jul 21 02:38 file3
-rw-r--r-- 1 terdon terdon 0 Jun 21 02:38 file4
-rw-r--r-- 1 terdon terdon 0 May 21 02:38 file5
-rw-r--r-- 1 terdon terdon 0 Apr 21  2015 file6
-rw-r--r-- 1 terdon terdon 0 Mar 21  2015 file7
Related Question