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

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Method 2

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.

Method 3

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.

Method 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.

Method 5

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x