[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to rename multiple files



On Mon, Dec 09, 2002 at 11:33:03PM -0800, Osamu Aoki wrote:
> On Mon, Dec 09, 2002 at 10:02:25PM -0600, Shyamal Prasad wrote:
> >     "drew" == drew cohan <debian@drewcohan.com> writes:
> > 
> >     drew> How do I rename all files in a directory matching the
> >     drew> pattern *.JPG to *.jpg in a bash shell script?  Thanks to
> >     drew> you guys I can check for the existence of jpgs in a
> >     drew> directory, but can't seem get 'mv' to rename them for me
> >     drew> (always complains that the last argument must be a
> >     drew> directory).
> > 
> > Still another way:
> > 
> > for i in *.JPG
> > do
> >   mv $i `basename $i .JPG`.jpg
> > done
> 
> Simplest alternative without sub-shell nor special command:
> 
> for i in *.JPG
> do
>   mv $i ${i%\.JPG}.jpg
> done
> 

I've been offline so I haven't seen all the responses but you'd better
put double quotes around the $i or it will fail if the file name has one
or more spaces in it.

-- 
The alternative is not plan or no plan. The question is: whose
planning? Should each member of society plan for himself or should the
paternal government alone plan for all?
    Rick Pasotto    rickp@telocity.com    http://www.niof.net



Reply to: