simple question about mv

Bill Michaelson bill at cosi.UUCP
Mon Jan 30 06:22:45 AEST 1989


In article <18216 at adm.BRL.MIL>, DEG41560 at ua1vm.ua.edu (Rob Smith) writes:
> ..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 should be aware that the mv command never even sees the asterisks
because the shell expands the wildcard into a list of files BEFORE passing
the argument list to the command.  What this amounts to is that the last
file in the expanded list becomes the target, and receives the contents
of all the other files in the expanded list.  Assuming there are no *.flop
files in the current directory,  you will effectively screw-up the last *.flip.

I can think of a partial solution to your problem, but being somewhat of a
novice at this business, it doesn't do exactly what you asked for.  Perhaps
someone else will jump in and help me out.  Try something like:

find . -name "*.flip" -exec mv {} {}.flop \;

This has three problems:

1) It appends '.flop' to the end of the names of the files, without
   dropping the .flip.  How does one get a substring in Bournese?

2) It walks through lower directories, which may be a problem.  Is there
   a way to prevent find from doing this?

3) I haven't tried it, so I'm not 100% certain it will do what I say.

Hmmm...  Come to think of it, I don't like my suggestion at all.  Oh well.
Food for thought, anyway.

-- 
Bill Michaelson - uh... princeton!mccc!cosi!bill, I think.
also at... Voice 609-771-6705  CompuServe 72416,1026



More information about the Comp.unix.questions mailing list