Unix commands almost always (with very few exceptions) have source before target. And most allow multiple sources before the final target if it makes sense to do so.
That includes scp
.
Some commands (like the GNU versions of cp
and mv
) have an option (e.g. -t
or --target-directory=DIRECTORY
) that allow you to put the target first - but the default is the standard "source(s) before target". This is mostly useful so you can have the target before the source when using something like find ... -exec cp -t target/ {} +
, or so you can avoid using -I {}
with xargs
(which is much slower, it causes xargs
to fork one command per arg, rather than fit as many as it can on each command line), e.g. ... | xargs -0r mv -t target/
instead of ... | xargs -0r -I {} mv {} target/
Without an explicit override option as mentioned above, "target before source" is almost unheard of - so rare that you're fully entitled to think "Huh? WTF?" if you ever encounter it.
If you need to scp
multiple files to multiple machines at once, do it in a for loop like this:
for h in host1 host2 host3... ; do
scp file1 file2 file3... "user@$h:/path/"
done
Or use pdcp
from Parallel Distributed Shell. pdsh
is packaged for most linux distributions.
e.g.
pdcp -w host1,host2,host3 file1 file2 file3 /path/to/target/
That's a very simple example, pdsh
has a config file you can use to define hosts and groups of hosts with arbitrary group names (e.g. all
, webservers
, dbservers
, gpunodes
, or whatever). You can then use them in pdsh
or pdcp
commands:
pdsh -g all 'uname -a ; uptime'
pdcp -g webservers index.html /var/www/
Unlike the for
loop above, it doesn't run commands or copy the files sequentially, one host at a time. It runs multiple commands in parallel, with reasonable limits based on the number of CPU cores your machine has.