solution in Perl (was Re: File Modification Dates)

Randal L. Schwartz @ Stonehenge merlyn at intelob.intel.com
Thu May 11 03:30:46 AEST 1989


In article <207 at psgdc>, rg at psgdc (Dick Gill) writes:
[wants code to get readable modtime from filename]
| I'll be happy to get a C program, shellscript or anything else
| that I can call from a Bourne shell script.

Ok, be happy.  Here's a very brief Perl program to do what you want:
################################################## snip snip
#!/usr/bin/perl
@s = stat($ARGV[0]);
@t = localtime($s[9]);
printf "%04d/%02d/%02d %02d:%02d:%02d\n",
	1900+$t[5], 1+$t[4], $t[3], $t[2], $t[1], $t[0];
################################################## snip snip
What?  You don't have Perl?  You'll probably have to write a small
C program that does the above as: (1) take the argument, (2) fstat it,
(3) look at the "mtime" field, (4) run it through "localtime",
and (5) print the result.

Or get Perl.  (Yeay, Larry!)

Just a Perl hacker,
-- 
***** PLEASE NOTE THE NEW ADDRESS *****
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095===\
{ on contract to BiiN, Hillsboro, Oregon, USA, until 14 May 1989     }
{ <merlyn at intelob.intel.com> ...!uunet!tektronix!biin!merlyn         }
{ or try <merlyn at agora.hf.intel.com> after 15 May 1989               }
\=Cute quote: "Welcome to Oregon... home of the California Raisins!"=/



More information about the Comp.unix.questions mailing list