Return to BSD News archive
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.uwa.edu.au!nodecg.ncc.telecomwa.oz.au!netbsd08.dn.itg.telecom.com.au!orca1.vic.design.telecom.com.au!news.tansu.com.au!picasso.cssc-syd.tansu.com.au!newshost!chrisb From: chrisb@stork.cssc-syd.tansu.com.au (Chris Bitmead) Newsgroups: comp.unix.bsd Subject: Re: Newbie Question: mv *.t *.txt ???? Date: 23 Feb 95 12:00:33 Organization: Telecom Australia Lines: 55 Message-ID: <CHRISB.95Feb23120033@stork.cssc-syd.tansu.com.au> References: <D41nyo.Mon@ritz.mordor.com> <3huiti$4lr@dagny.galt.com> NNTP-Posting-Host: stork.cssc-syd.tansu.com.au In-reply-to: alex@phred.org's message of 16 Feb 1995 04:05:06 GMT In article <3huiti$4lr@dagny.galt.com> alex@phred.org (alex wetmore) writes: >Hany Nagib (hany@ritz.mordor.com) wrote: >: I know this must be a very simple question, but it's not in the FAQ. >: "mv" looks like it works exactly like "rename" in DOS, except when using >: wild card. For example if I wanted to rename all my .t files to .txt, I >: expect "mv *.t *.txt" to work .. but it doesn't. Why ? And how do I >: accomplish this in BSD unix ? > >DOS leaves globbing (converting wildcards into filenames) up to application >programs, while Unix does it in the shell. So the "mv" program sees >the command line "mv a.t b.t c.t" (if your directory has the files a.t, >b.t, and c.t, but no .txt files), and doesn't know how to handle that. > >Try this: (in sh) > >for oldf in *.t >do > newf=`echo $oldf | sed 's/.t$/.txt/g'` > mv $oldf $newf >done I think this is easier: for f in *.t do mv $f `basename $f .t`.txt done or to make a script out of it: #!/bin/sh for f in *.$1 do mv $f `basename $f $1`.$2 done > >I'm sure there are shorter ways to do it, but the above works for >me. You could turn it into the shell script: > >#!/bin/sh >for oldf in *.$1 >do > newf=`echo $oldf | sed "s/.$1\$/.$2/g"` > mv $oldf $newf >done > >which takes the old extension as argument one, the new extension >as argument two, and renames everything. > >alex -- Chris Bitmead chrisb@ind.tansu.com.au