Computing.Net > Forums > Unix > Timestamp for files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Timestamp for files

Reply to Message Icon

Name: johndee
Date: February 16, 2004 at 09:10:22 Pacific
OS: HP-UX
CPU/Ram: 512
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: February 16, 2004 at 15:28:55 Pacific
Reply:

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 xyear

date '+%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"


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Timestamp for files

Polling for file arrival www.computing.net/answers/unix/polling-for-file-arrival/5603.html

Check for files with different ext www.computing.net/answers/unix/check-for-files-with-different-ext/7346.html

Extracting I-node details for file www.computing.net/answers/unix/extracting-inode-details-for-file/4219.html