tags:

views:

56

answers:

3

I tried cp initial.txt {foo,bar,baz} but get baz is not a directory. And cp initial.txt foo bar baz doesn't work either.

Is there a way I can do this without making a shell script and looping and invoking cp multiple times? I'm thinking there has to be a succinct way of doing this.

A: 

No, there's not. You have to loop.

cp does take multiple arguments, but it's only to copy all but the last argument into the last argument, which must then be a directory.

wnoise
I'm looking for creative workarounds, not a "no you cannot" strict RTFM type useless answer.
meder
@meder: is "for i in foo bar baz; do cp initial.txt $i; done" really a problem? Really?
wnoise
`tee foo bar baz < initial.txt` is much more succinct.
meder
+6  A: 

You can use tee. See this answer on superuser.com:

http://superuser.com/questions/32630/parallel-file-copy-from-single-source-to-multiple-targets

rsenna
+4  A: 

xargs in general is a way to turn loops into single commands, and it will work just fine here, too e.g.: echo foo bar baz | xargs -n1 cp initial.txt

However, this does invoke cp multiple times. On the positive side, you can run the cp commands in parallel with the -P option to xargs.

frankc