From owner-freebsd-questions Sun Oct 14 4:56:18 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id A29C637B40B for ; Sun, 14 Oct 2001 04:56:12 -0700 (PDT) Received: from hades.hell.gr (patr530-b078.otenet.gr [195.167.121.206]) by mailsrv.otenet.gr (8.11.5/8.11.5) with ESMTP id f9EBu1v03998; Sun, 14 Oct 2001 14:56:01 +0300 (EEST) Received: (from charon@localhost) by hades.hell.gr (8.11.6/8.11.6) id f9EBiQn54105; Sun, 14 Oct 2001 14:44:26 +0300 (EEST) (envelope-from charon@labs.gr) Date: Sun, 14 Oct 2001 14:44:25 +0300 From: Giorgos Keramidas To: Randy Bush Cc: questions@FreeBSD.ORG Subject: Re: date of a file Message-ID: <20011014144425.A52653@hades.hell.gr> References: <73720831@toto.iv> <15303.43126.44123.116068@guru.mired.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.22.1i X-GPG-Fingerprint: C1EB 0653 DB8B A557 3829 00F9 D60F 941A 3186 03B6 X-URL: http://labs.gr/~charon/ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Randy Bush 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