Why does "ls -all" show time for some files but only year for others?

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

The time represented is modification time. Please note that ls -all is the same thing as ls -l -a, which is different from ls --all. There is no reason to use double l in your example. If you want to see the modification time for each file, you can use ls -al --full-time.


If the date/time that it is trying to display is in the past six months, ls displays the date and the time.  If it's longer ago than six months — or if it's in the future — ls displays the date and the year.

As stated in the other answers,

  • ls -ll is equivalent to ls -l, and
  • ls -all is equivalent to ls -al, which is equivalent to ls -a -l, ls -l -a, and ls -la.

With the -l option, ls displays the modification date/time of files (including directories, since "everything is a file"), unless

  • -c is also specified, in which case it displays change time, or
  • -u is also specified, in which case it displays access time.

See ls(1) for more information.

Tags:

Ls