46

If you issue the ls -all command some files are displayed with the timestamp containing the year without the time and others with the timestamp containing the time but not the year. Why does this happen? Is the timestamp representative of the time the file was created at?

enter image description here

1
  • 19
    You are using -all. Note the last L is superfluous, because all does not stand for the word "all" but for -a (show all files) and -l (long listing format). All together, ls -al is the same as what you are using.
    – fedorqui
    Commented Oct 21, 2015 at 14:55

6 Answers 6

42

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
1
  • 4
    Worth noting that times in the future will also show the year rather than time. This can happen if you exchange files between hosts where the clock is not in sync.
    – kasperd
    Commented Oct 21, 2015 at 9:04
31

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.

2
  • 7
    In GNU ls for normal use --time-style=long-iso could be more useful. --full-time shows seconds including nine ciphers (!) after the decimal dot which is normally not needed. Commented Oct 21, 2015 at 8:30
  • 1
    --full-time implies -l, so you could just use ls -a --full-time.
    – kasperd
    Commented Oct 21, 2015 at 9:00
6

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.

4

This output is tuned for maximal information content: when the time is "close enough" to the current time (not entirely sure, but I'm guessing within six months) the year is elided and the time of day shown instead. Otherwise, the year is shown. This is the default mostly because you likely don't care as much about the precise time-of-day something was modified, if that time is years ago. GNU coreutils ls has the --time-style option, to control this explicitly.

1

To get full time for old files also, I personally use:

alias ls='ls --time-style=long-iso -Altr'

So I don’t have such issues locally. However it remains a problem using ftp. I am uploading old photos to my website using lftp’s mirror option and some are uploaded though they haven’t changed nor their timestamps. I am trying to figure out if this is e.g. a timezone clash but I can’t because the file time is not displayed by default and the ls option "--time-style=long-iso" is not accepted by the ftp server.

1
  • The following command displays full date and time in lftp with most recent file last: cls -altr --time-style="%Y-%m-%d-%H-%M" Commented Jan 16 at 1:27
0

Have you realized something? It just appear the hour time on 20 October, which is today, that means that it will show the last time you modified the file, but, in other days which aren't today, it will only show the date without the time.

It turns out that it is not this, as answered by Thomas. I just tried to use the deduction method, not assured to have a correct conclusion after all.

2
  • 1
    Aug 6 19:50 .config, Aug 6 19:48 VNCHOWTO. Commented Oct 20, 2015 at 23:38
  • Perfect, I just did a deduction thing looking the dates and connecting the points, which cannot be always a perfect conclusion.
    – ranu
    Commented Oct 20, 2015 at 23:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .