Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can you scp a file to multiple locations in the same command?

For example:

scp file.txt,

Or would it be more practical to create a bash script that has all the hosts already in it and it would just take a file as the argument?

share|improve this question
up vote 12 down vote accepted

Let's say you have a file (destfile.txt) with user@host-values, one on each line. Then you could do like this:

for dest in $(<destfile.txt); do
  scp ourfile.txt ${dest}:remote/path/
share|improve this answer
This works! Still a handful to type out though. Perhaps there's a way to simplify that. – Andrew Sep 22 '11 at 21:02
@Andrew, if you change the for-loop into while read dest; do, it will read from standard input. Put it in a script and feed the destfile.txt into it (e.g., ./ <destfile.txt). – Kusalananda Sep 22 '11 at 21:19
Thank you. That does simplify it a bit. – Andrew Sep 22 '11 at 21:24
cat file.txt | tee >(ssh "cat > file.txt") \
                   >(ssh "cat > file.txt")

tar cz file1 file2 file3 | tee >(ssh "tar xz") \
                               >( ... )
share|improve this answer

Looks like a job for parallel-scp - this implements a set of commands that allow for scp commands to be run on multiple systems at once. It will allow for the copying of files in parallel to a set of machines.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.