Copying to multiple directories

Philippe Casgrain casgrain at magellan.umontreal.ca
Thu Mar 11 08:15:04 PST 2004


"Kuestner, Bjoern" <Bjoern.Kuestner at drkw.com> a écrit :

> Uh, ah, I don't exactly understand how Brian's solution works (it is a
> solution, Brian, right?), and I hesitate to run any command that I 
> don't
> understand "just to find out". (c:
>
> (It's this "echo" that confuses me ... I would have expected something 
> like
> "exec" or ` `? And then there are no ' ' or " " afterwards for what is
> handed to "echo"?)

Here is Brian's command (quite clever, IMHO):

	ls -d /Users/*/Library | xargs -I % echo cp fileA %

This command lists all Library folders for all users (that's the first 
part in front of the vertical pipe "|" character) and then sends that 
list to xargs, which massages it to add the string "cp fileA " to each 
line. Everything is then written to stdout using echo.

You can run this command as-is from any terminal window, it should 
simply produce a list of your Library folders prepended with "cp fileA 
". Which doesn't do anything; you would have to copy-paste each line 
and execute it from the command line.

If you want these commands to do anything useful, simply pipe the list 
of commands into sh:

	ls -d /Users/*/Library | xargs -I % echo cp fileA % | sh

Philippe 


This e-mail message is intended only for the named recipient(s) above and may contain information that is confidential, proprietary, privileged, and /or exempt from 
disclosure under applicable law. If you have received this message in error, or are not he named recipient(s), please immediately notify the sender and delete this e-mail 
message.
 



More information about the X-Unix mailing list