[Canberra-pm] Most efficient way to find the ISO 8602 date of a the most recently modifiec file in a directory

Kim Holburn kim at holburn.net
Wed May 3 22:40:34 PDT 2006


Here's a script I use to get the date from log files It's a bit  
different to what you want as it takes the first word of the first  
line of a log file as an epoch timestamp.:


#!/usr/bin/perl -w

use strict;

use POSIX qw(strftime);

my $file = $ARGV[0];
my $test = 1;
if ($file eq "-y") { shift; $test = 0; $file = $ARGV[0]; }
my $file1 = $file;
if ($file =~ /z$/i) { $file1 = "zcat $file|"; }
my ($time, $junk);
if (open (FILE, $file1)) {
   my $line = <FILE> ;
   close FILE;
   ($time, $junk) = split (/\t/, $line, 2);
}
else { print  "Couldn't open file ($file)"; exit (1); }

print strftime ("%Y-%m-%dT%H:%M:%S \n", localtime ($time));



On 2006 May 04, at 12:21 PM, Kim Holburn wrote:

> I use Posix::strftime
>
> On 2006 May 04, at 11:41 AM, <John.Hockaday at ga.gov.au>
> <John.Hockaday at ga.gov.au> wrote:
>
>> Hi All,
>>
>> I am trying to find the date of the most recently modified file in a
>> directory.  I thought that someone should have done this already.
>> I have
>> been looking into:
>>
>> Date::Calc(Time_to_Date)
>> File::stat
>> localtime
>>
>> but if someone has already done this can I please have your code?
>>
>> The output should be in ISO 8601 format.  IE, 2006-05-04T11:21:20
>> This
>> latter part I can easily do with printf.
>>
>> Thanks.
>>
>>
>> John Hockaday
>> Geoscience Australia
>> GPO Box 378
>> Canberra ACT 2601
>> (02) 6249 9735
>> http://www.ga.gov.au/
>> john.hockaday\@ga.gov.au
>> _______________________________________________
>> Canberra-pm mailing list
>> Canberra-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/canberra-pm
>>
>
> -- 
> Kim Holburn
> Security Manager, National ICT Australia Ltd.
> Ph: +61 2 61258620 M: +61 417820641  F: +61 2 6230 6121
> mailto:kim.holburn at nicta.com.au  aim://kimholburn
> skype://kholburn - PGP Public Key on request
> Cacert Root Cert: http://www.cacert.org/cacert.crt
> Aust. Spam Act: To stop receiving mail from me: reply and let me know.
>
> Use ISO 8601 dates [YYYY-MM-DD] http://www.saqqara.demon.co.uk/
> datefmt.htm
> Democracy imposed from without is the severest form of tyranny.
>                            -- Lloyd Biggle, Jr. Analog, Apr 1961
>
>
>
>
> --
> Kim Holburn
> Network Consultant
> Ph: +61 2 61258620 M: +61 417820641  F: +61 2 6230 6121
> mailto:kim at holburn.net  aim://kimholburn
> skype://kholburn - PGP Public Key on request
> Cacert Root Cert: http://www.cacert.org/cacert.crt
> Aust. Spam Act: To stop receiving mail from me: reply and let me know.
>
> Use ISO 8601 dates [YYYY-MM-DD] http://www.saqqara.demon.co.uk/
> datefmt.htm
> Democracy imposed from without is the severest form of tyranny.
>                            -- Lloyd Biggle, Jr. Analog, Apr 1961
>
>
> _______________________________________________
> Canberra-pm mailing list
> Canberra-pm at pm.org
> http://mail.pm.org/mailman/listinfo/canberra-pm
>

--
Kim Holburn
Network Consultant
Ph: +61 2 61258620 M: +61 417820641  F: +61 2 6230 6121
mailto:kim at holburn.net  aim://kimholburn
skype://kholburn - PGP Public Key on request
Cacert Root Cert: http://www.cacert.org/cacert.crt
Aust. Spam Act: To stop receiving mail from me: reply and let me know.

Use ISO 8601 dates [YYYY-MM-DD] http://www.saqqara.demon.co.uk/ 
datefmt.htm
Democracy imposed from without is the severest form of tyranny.
                           -- Lloyd Biggle, Jr. Analog, Apr 1961




More information about the Canberra-pm mailing list