Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Pls I urgent need someone to help with setting the timestamp format so that ls -l or ll on files created or modified have the year (eg 2004) as part of the timestamp
Rgds
John

Hi:
Every unix/linux variant I've used sets the 8th field of 'ls -l' to the time if the file is created in the last 6 months. I don't know of a way of changing this.
I ran the ls -l thru an awk script and if the eighth field has a ":" I change it to the current year. that is, unless the 6th field is greater than the current month signifying the last half of last year. Then I subtract one from the current year.
I'm using nawk; You may to change this to awk:
#!/bin/ksh
integer xmon
integer xyeardate '+%m %Y'|read xmon xyear
ls -l |nawk ' {
if(index($8, ":") )
{
if(month_no($6) > mm)
$8=yy-1
else
$8=yy
}
printf("%s\n", $0)
}function month_no(mm) {
if(mm == "Jan")
return 1
if(mm == "Feb")
return 2
if(mm == "Mar")
return 3
if(mm == "Apr")
return 4
if(mm == "May")
return 5
if(mm == "Jun")
return 6
if(mm == "Jul")
return 7
if(mm == "Aug")
return 8
if(mm == "Sep")
return 9
if(mm == "Oct")
return 10
if(mm == "Nov")
return 11
if(mm == "Dec")
return 12
return 0
}' mm="$xmon" yy="$xyear"

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |