Date: Sun, 14 Oct 2001 14:44:25 +0300 From: Giorgos Keramidas <charon@labs.gr> To: Randy Bush <randy@psg.com> Cc: questions@FreeBSD.ORG Subject: Re: date of a file Message-ID: <20011014144425.A52653@hades.hell.gr> In-Reply-To: <E15sJ9L-000Hfy-00@rip.psg.com> References: <73720831@toto.iv> <15303.43126.44123.116068@guru.mired.org> <E15sJ9L-000Hfy-00@rip.psg.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Randy Bush <randy@psg.com> wrote: > > date +%y%m%d-%H%M%S -jf "%b %d %H:%M:%S" `ls -lT filename | awk ' { print $6, $7, $8, $9 } '` > > i have tried many variations on this, and all fail as follows: Here's a perl variation that I've checked with zsh as my shell. Quoting might be way different in tcsh, in which case you're much better off creating a standalone script as shown at the end of this message: % perl -e 'foreach $filename (@ARGV) { \ @sdata = stat($filename); \ print "${filename}: " . $sdata[9] . "\n"; \ }' FILE ... You can use strftime() to format sdata[9] (which is the mtime field of stat()'s output) to whatever you want. Note that using strftime will require a `use POSIX qw(strftime)' added to the code. That would make the final code: % perl -e 'use POSIX qw(strftime); \ foreach $filename (@ARGV) { \ @sdata = stat($filename); \ print "${filename}: " . \ strftime("FMT", gmtime($sdata[9])) . "\n"; \ }' FILE ... Here's a slightly different version of the code that you can write to a standalone script, shown in action: % cat mtime.pl #!/usr/bin/perl use POSIX qw(strftime); ARG: foreach $filename (@ARGV) { @sdata = stat($filename); next ARG unless (defined(@sdata)); $mtime = $sdata[9]; print "${filename}: " . strftime("%y%m%d-%H%M%S", gmtime($mtime)) . "\n"; } % perl mtime.pl mtime.pl /COPYRIGHT /etc mtime.pl: 011014-113245 /COPYRIGHT: 001120-120312 /etc: 011008-170105 -giorgos To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011014144425.A52653>