home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!destroyer!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!acs.ucalgary.ca!cuugnet!edwardsk
- From: edwardsk@cuug.ab.ca (Kenneth Edwards 268-6500)
- Subject: Re: How to rename a group of files with wild cards (* and ?)?
- Message-ID: <1992Nov5.031528.16167@cuug.ab.ca>
- Organization: Calgary UNIX Users' Group
- References: <1992Oct31.062644.13968@constellation.ecn.uoknor.edu> <1992Nov4.052804.4790@bohra.cpg.oz.au>
- Date: Thu, 5 Nov 1992 03:15:28 GMT
- Lines: 38
-
- In article <1992Nov4.052804.4790@bohra.cpg.oz.au> johnr@bohra.cpg.oz.au (John Reid) writes:
- >u235@rex.chb.uokhsc.edu (Yung-Jin Lee) writes:
- >
- >>Is there anyway to rename a group of files with
- >>wild cards (* and ?)? I've tried mv and cp and
- >>I am not able to do this.
- >
- >To move a group of files called fred* in directory olddir to newdir try
- >
- >for file in `cd oldir ; ls fred*`
- >do
- > mv "$olddir/$file" "$newdir"
- >done
-
- Well that would work, but I think it is easier.
- To move a group of files called fred* in directory olddir to newdir try
-
- mv olddir/fred* newdir
-
- please tell us what shell you are using so we can give an appropriate
- answer, however to rename a group of files in ksh - you do something like
-
- for file in fred*.text
- do
- mv $file ${file%.text}.txt # renames all .text files to .txt
- OR mv $file f.${file#project} # renames all fred*.text files to f.*.text
- OR mv $file `echo $file | tr "[a-z]" "[A-Z]"` # renames all fred* to FRED*
- OR mv $file `expr $file 'fred\(.*\)\.text'` # quite probably does bad stuff
- OR whatever you should probably check first by generating the names before
- you do the rename and using an echo in front of the mv until you like the
- list of names you get
- done
-
- --
- _____________________________________________________________________________
- Feeling amorous, she looked under the sheets and cried, OH NO it's micro soft
-
-
-