Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!spool.mu.edu!uunet!mcsun!inesc!unl!unl!jpc From: jpc@fct.unl.pt (Jose Pina Coelho) Newsgroups: comp.sys.amiga.introduction Subject: Re: Wildcards in the CLI Message-ID: Date: 8 May 91 16:22:34 GMT Article-I.D.: terra.JPC.91May8162234 References: <1991Apr25.100919.21595@fwi.uva.nl> <21179@cbmvax.commodore.com> Sender: news@fct.unl.pt (USENET News System) Organization: Universidade Nova de Lisboa -- Lisbon, Portugal Lines: 71 In-Reply-To: mwm@pa.dec.com's message of 7 May 91 15:02:30 GMT In article mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) writes: > > >Copy files [to] [file/dir] > > ^^^^ why the f*** ? > > Because one could want to specify the parameters in a different order. For > example, "copy to destination from source". > > For utilities that generate command lines, this is what makes the > multi-source-file version copy work reasonably. For those utilities, in unix, you find a powerfull mix of awk, sed, find & perl, on the other hand, in UNIX, it's the shell that is in charge of expanding the wild names, leaving the programs with an easy interface and simple works. when you do 'ls *.c' the shell will build a list of the files that match the expression, and will call ls with those arguments. Only if there are no matches, will ls get *.c, which it will try to copy, and fial with 'cp: *.c: No such file or directory' > For instance, on unix, to move all the .c files out of a directory > requires exec'ing one cp per file, even though cp takes multiple > arguments. You do: > > find . -name '*.c' -exec cp '{}' dest \; That finds all files that match a pattern in a directory tree (bellow us) and execs copy for each file that does, that's slow, you have quite better options: find . -type d -print | awk '{ printf "cp %s/*.c dest\n", $0 }' | sh this will: Find all dirs, Create a command line to copy from each dir, pass them, to the shell for wildcard expansion and execution. for i in `find . -type d -print` do cp $i/*.c dest done > > If Unix had an AmigaDOS 2.0 copy, you could do it with a single > invocation of copy as: > > find . -name '*.c' -print | xargs copy to dest You can do that as: cp `find . -name '*.c' -print` dest or (depends on your shell flavour) cp $(find . -name '*.c' -print) dest What I was barfing at was mostly the [to], it has no business there. If I want to copy something then I must tell WHERE to, and it can be only one thing, the last one (or the first one, though