From owner-freebsd-questions@FreeBSD.ORG Tue May 27 19:45:25 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B705A37B401 for ; Tue, 27 May 2003 19:45:25 -0700 (PDT) Received: from Gina.esfm.ipn.mx (esfm.ipn.mx [148.204.102.61]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4A6BA43F3F for ; Tue, 27 May 2003 19:45:23 -0700 (PDT) (envelope-from mrspock@esfm.ipn.mx) Received: from Gina.esfm.ipn.mx (localhost [127.0.0.1]) by Gina.esfm.ipn.mx (8.12.6p2/8.12.6) with ESMTP id h4S2ibM2001278; Tue, 27 May 2003 21:44:37 -0500 (CDT) (envelope-from mrspock@esfm.ipn.mx) Received: from localhost (mrspock@localhost)h4S2iWfS001275; Tue, 27 May 2003 21:44:36 -0500 (CDT) X-Authentication-Warning: Gina.esfm.ipn.mx: mrspock owned process doing -bs Date: Tue, 27 May 2003 21:44:32 -0500 (CDT) From: Eduardo Viruena Silva To: Vince Hoffman In-Reply-To: <3500515B75D9D311948800508BA37955014BDB91@EX-LONDON> Message-ID: <20030527213231.B1115@Gina.esfm.ipn.mx> References: <3500515B75D9D311948800508BA37955014BDB91@EX-LONDON> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: 'Joachim Dagerot' cc: freebsd-questions@freebsd.org Subject: RE: shell programming - how to write a script that renames files after their last moddate? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 May 2003 02:45:26 -0000 On Tue, 27 May 2003, Vince Hoffman wrote: > > > This is certainly not freeBSD specific and probably I'm annoying > > someone for being off-topic but please be patient and hint me on where > > to find good resources in shell-programming. > > > http://www.shelldorado.com/ > isnt bad. otherwise comp.unix.shell is always worth a look. > > > > > > > I could use some help in writing a script that renames all files in a > > directory tree to the files last modified date, example usage: > > > > > daterename "Img_" *.jpg > > > > the command above will rename all *.jpg files to "Imag_".jpg ============================= #!/bin/tcsh set prefix=$1 shift while ( "$1" != "" ) set ext=`expr "$1" : ".*\(\..*\)"` set newname=$prefix`stat -f "%Sm" -t "%F_%H:%M:%S"` echo moving $1 to $newname$ext mv $1 $newname$.ext shift end =========================== BUGS: I'm not sure "stat" works in 4.x If two [or more] files are created at exactly the same time, the one with the last name --in lexicographic order-- will overwrite the others. Hope it helps.