But it's not always true, that if file is created only in the current year, then only time will be show.
Consider the case that today is "2nd Jan 2011", and file is created on "29th Dec 2010". Year has been changed since the time of file creation (2010 to 2011). But still it will show the date in dd mon hh:mm (29 Dec 3:54) format. Kindly consider this case as well.
I'm sorry I did not read it fully. Indeed, it's not creation time but modified time.
man ls , gives
If the time of last modification is greater than six months ago, or any time in the future, the year is substituted for the hour and minute of the modification time.
So, need to find a logic here to get the years!!!.
This is not the exact solution. I am not that much efficient in Unix coding. But by seeing your code, I came to know, that you have searched : in $8 parameter and if it not found, then you printed $8 as it is (as it will be already a year format) and if its found, you replaced $8 with current year (that is WRONG, we need to compare the months as well in that case, if month of file modification is greater than the current month of the current year, then we need to do year=year-1 else year=year). How this will help you (eventually me ) to write a code for that.
I appreciate your efforts. But whatever you have done can be done by the code below as well--
Can you past a line from ls that you think the awk code will not work against? i.e paste a line from your ls output where "month of file modification is greater than the current month of the current year"? Maybe I can modify the logic.
Well, for that I need to change the date/time of the system, for that privilidges not granted to me.
Just set your system date to '29-Dec-2010', make a file, now again set your date to '2-Jan-2011', now execute your command. Let me know if your code work perfectly.
Regards,
Manu
---------- Post updated 08-24-11 at 01:16 AM ---------- Previous update was 08-23-11 at 10:28 PM ----------