Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 May 2003 21:44:32 -0500 (CDT)
From:      Eduardo Viruena Silva <mrspock@esfm.ipn.mx>
To:        Vince Hoffman <Vince.Hoffman@uk.circle.com>
Cc:        freebsd-questions@freebsd.org
Subject:   RE: shell programming - how to write a script that renames files  after their last moddate?
Message-ID:  <20030527213231.B1115@Gina.esfm.ipn.mx>
In-Reply-To: <3500515B75D9D311948800508BA37955014BDB91@EX-LONDON>
References:  <3500515B75D9D311948800508BA37955014BDB91@EX-LONDON>

next in thread | previous in thread | raw e-mail | index | archive | help
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_<date>".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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030527213231.B1115>