Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!pasteur!ames!elroy!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.wizards Subject: Re: simple question about mv Message-ID: <4435@jpl-devvax.JPL.NASA.GOV> Date: 15 Feb 89 23:03:43 GMT References: <18217@adm.BRL.MIL> <228@torch.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA. Lines: 54 In article <228@torch.UUCP> richard@torch.UUCP (Richard Nuttall) writes: : DEG41560@ua1vm.ua.edu (Rob Smith) writes: : : >HI, : : > 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 : : I prefer the C shell foreach, which is really neat : : : foreach i (*.flip) : echo $i : mv $i $i:r.flop : end Yes, you can use csh for that, but it's an awful lot of typing. If you have perl, you can put this script into your system as "rename": #!/usr/bin/perl $subst = shift; @ARGV = <*> if $#ARGV < 0; foreach $name (@ARGV) { $_ = $name; eval "$subst;"; die $@ if $@; rename($name,$_) unless $name eq $_; } You can now say things like: rename 's/\.flip$/.flop/' # rename *.flip to *.flop rename s/flip/flop/ # rename *flip* to *flop* rename 's/^s\.(.*)/$1.X/' # switch sccs filenames around rename 's/$/.orig/ */*.[ch]' # add .orig to your source files in */ rename 'y/A-Z/a-z/' # lowercase all filenames in . rename 'y/A-Z/a-z/ if -B' # same, but just binaries! or even rename chop *~ # restore all ~ backup files The script could of course be modified to be verbose, or to confirm, or to get filenames from find, or to not wipe out existing files. For that matter, you could probably modify it into a C compiler if you tried hard enough. :-) Larry Wall lwall@jpl-devvax.jpl.nasa.gov