Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!vrdxhq!vsedev!logan From: logan@vsedev.VSE.COM (James Logan III) Newsgroups: comp.unix.wizards Subject: Re: simple question about mv Message-ID: <1300@vsedev.VSE.COM> Date: 29 Jan 89 20:59:15 GMT References: <18217@adm.BRL.MIL> Reply-To: logan@vsedev.VSE.COM (James Logan III) Organization: VSE Software Development Lab Lines: 62 In article <18217@adm.BRL.MIL> DEG41560@ua1vm.ua.edu (Rob Smith) writes: # I know this is simple, but then again, so am I. What if I want to mv a bunch # of files with the same suffix to another suffix. The following does not # work # # mv *.flip *.flop # # what does? I'm under Ultrix 2.2. I'm doing it by hand, but I'd like to # be able to do wild card renames, ala DOS. You will have to do this with a "for" loop. If you are using the Bourne or the Korn shell, you can use the following loop. If you're using the C shell, you're on your own. for FILE in *.flip; do NOEXTEN=`basename $FILE .flip`; echo $FILE ${NOEXTEN}.flop; mv $FILE ${NOEXTEN}.flop; done; I like having the echo in the above example so that if I make a typo I can see the problem, before it's too late, and hit the interrupt key. That loop can be generalized into a shell script like this one: ------------------------------------------------------- : # mvex.sh James Logan Sun Jan 29 15:44:09 EST 1989 # Move all files with one extension to a new extension. # # # Check the parameters. # if test $# -ne 2; then echo >&2 "usage: $0 oldextension newextension"; exit 2; fi; # # These variables can be optimized out, but are used for clarity. # OLDEXTENSION=$1; NEWEXTENSION=$2; # # Move each file one at a time. # for FILE in *$OLDEXTENSION; do NOEXTEN=`basename $FILE $OLDEXTENSION`; mv $FILE ${NOEXTEN}${NEWEXTENSION}; done; exit 0; ------------------------------------------------------- -Jim -- Jim Logan logan@vsedev.vse.com VSE Software Development Lab uucp: ..!uunet!vsedev!logan (703) 418-0002 inet: logan%vsedev.vse.com@uunet.uu.net