[X-Unix] Copying to multiple directories

Stroller MacMonster at myrealbox.com
Thu Mar 11 07:21:05 PST 2004


On Mar 11, 2004, at 12:38 pm, Harvey Riekoff wrote:

> Also when I run the command "$ ls -d /Users/*/Library | xargs -I % 
> echo cp fileA %"  I get the following message "su: $: Command not 
> found"

"$" is not part of the command, but is the placeholder you normally see 
at a user's command shell when it's waiting for an instruction to be 
typed in. So when someone posts an email message with a line beginning 
"$" it means "type the rest of this line in at the terminal". ("#" is 
the root's command prompt, so we're ignoring file & directory 
permissions on your users' folders for the present.)

So what Brian is actually suggesting you do is type `ls -d 
/Users/*/Library | xargs -I % echo cp fileA %` in at the terminal.
(I use these `quotes` to indicate a command in the same way as "$" 
because they have a similar significance to the shell, too).

In fact, what Brian's command will actually do is display the same 
output that he's pasted into his message - again it is convention that 
the lines following a $ are exactly what the terminal displays, copied 
& pasted into the email message.

So the `echo` command is run (which means "show the rest of the line on 
the screen") instead of the `cp` command - we don't see the `echo`, we 
just see what comes after it.
$ ls -d /Users/*/Library | xargs -I % echo cp fileA %
   cp fileA /Users/bpm/Library
   cp fileA /Users/jasonp/Library
   cp fileA /Users/jmh/Library

What Brian is doing in his posting is DEMONSTRATING the use of the pipe 
("|") and the `xargs` command (see `man xargs`), suggesting that you 
run this, change "fileA" to the name of the file you actually want to 
copy, and check that it will do what you require. Then run the command 
again, but WITHOUT the `echo` (use the up-arrow key to bring up the 
previous line for editing) to actually perform the copying you require.

Notes:
- the `ls -d /Users/*/Library` actually does the shell expansion you 
require.
- `man xargs` explains:
      -I replstr
              Execute utility for each input line, replacing one or more
              occurences of replstr...
- I believe the "%" is a placeholder to enclose the command being 
executed by `xargs`, however I don't immediately find this clearly 
documented anywhere.

HTH,

Stroller.



More information about the X-Unix mailing list