Search code examples
unixls

Why does it seem completely random if ls -lrt returns last modifed year or not?


Here are the results of a ls -lrt command in unix:

-rw-r--r--   1 blah      blah          846       Apr 18  2013 filetype1.log
-rw-r--r--   1 blah      blah          290338533 Jan  3 00:59 filetype2.log

Why does one conveniently return the year while the other just has month, day, and time stamp? How can I always get the year?

EDIT: Here's an example where the last edit time was NOT within the current year and still no year:

-rw-r--r--   1 blah      blah       689466 Dec 31 23:59 filetype2.log
-rw-r--r--   1 blah      blah       689591 Jan  1 00:59 filetype2.log

Solution

  • From the GNU Coreutils manual:

    10.1.6 Formatting file timestamps

    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.