Copying multiple files on linux

1

I have a linux machine with folders named numerically. How can I securely copy ranges of these folders to another server? The source machine runs tcsh, the target bash. At the moment, from the directory containing the data I want to copy, I am using the following command:

scp -r [2042-2046] user@target:home/user/destination_folder

The source machine asks for my password for target and appears to copy files, but nothing arrives on the target machine. There are no errors. If however, I replace the range of folders with a single folder name, then the copying works fine:

scp -r 2042 user@target:home/user/destination_folder

however, this would mean repeating the scp command 5 times and putting my password in everytime, which seems very inefficient, especially for larger ranges.

218

Posted 2014-10-27T10:36:53.547

Reputation: 137

Answers

1

The range

[2042-2046]

appears to be interpreted as file 2 and file 6.

The following gives the required range:

204[2-6]

218

Posted 2014-10-27T10:36:53.547

Reputation: 137

0

You could use a tar stream over SSH:

tar cvf --include='204[2-6]' - . | ssh user@target "cd /home/destination/folder; tar xvf -"

Fegnoid

Posted 2014-10-27T10:36:53.547

Reputation: 839

0

Use a bash brace expansion expression:

scp -r {2042..2046} user@target:home/user/destination_folder

Note that brace expansion happens before parameter expansion, so you cannot write this:

start=2042
end=2046
scp -r {$start..$end} user@target:home/user/destination_folder

without an eval

glenn jackman

Posted 2014-10-27T10:36:53.547

Reputation: 18 546