开发者

bash: Is there a shortcut to copying a file to multiple places without looping/bash script?

I tried cp initial.txt {foo,bar,baz} but get baz is not a director开发者_StackOverflow中文版y. 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.


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

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜