bash 通过bash脚本scp一堆文件:一定有更好的方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4728752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 23:17:51  来源:igfitidea点击:

scp a bunch of files via bash script: there must be a better way

bashloopsscp

提问by David Oneill

I currently have the following bash script:

我目前有以下 bash 脚本:

for a in `seq 16 75`; 
do scp doneill@server:/mnt/device/folder/numbered_file$a.txt ./; 
done;

while this does work, it is very slow. Each file, the request to the sever takes about 4-7 seconds, then sending the file takes another 3 or so seconds.

虽然这确实有效,但速度很慢。每个文件,请求到服务器大约需要 4-7 秒,然后发送文件又需要 3 秒左右。

Is there a way to do this that involves only 1 command sent to the server (to minimize the time my VPN spends sending receiving each individual command)? Normally, I would do something like scp doneill@server:/mnt/device/folder/numbered_file*but there are many thousands of files in the folder that I don't want to copy. I need to get only those few (defined by the sequence).

有没有办法做到这一点,只涉及发送到服务器的 1 个命令(以最大限度地减少我的 VPN 用于发送接收每个单独命令的时间)?通常,我会做类似的事情,scp doneill@server:/mnt/device/folder/numbered_file*但文件夹中有成千上万个我不想复制的文件。我只需要得到那些(由序列定义)。

采纳答案by Ignacio Vazquez-Abrams

In bash:

在 bash 中:

scp doneill@server:/mnt/device/folder/numbered_file{16..75}.txt ./

回答by tdammers

rsync should do the trick: http://www.manpagez.com/man/1/rsync/

rsync 应该可以解决问题:http: //www.manpagez.com/man/1/rsync/

You may have to fiddle a bit with the parameters, but done right, it's probably the fastest way of transferring files over ssh.

您可能需要对参数稍加改动,但如果做得对,这可能是通过 ssh 传输文件的最快方式。

回答by SiegeX

Does this work with bash?

这适用于 bash 吗?

scp doneill@server:/mnt/device/folder/numbered_file{16..75}.txt ./