我正在尝试scp多个文件从源到destination.The场景是源文件名与目标文件不同
这是我想要做的SCP命令
scp /u07/retail/Bundle_de.properties rgbu_fc@<fc_host>:/u01/projects/MultiSolutionBundle_de.properties基本上,我确实有超过7个文件,我正在尝试分离scps来实现它。所以我想把它连接到一个scp上来传输所有的文件
我在这里尝试的scp命令很少-
$ scp /u07/retail/Bundle_de.properties rgbu_fc@<fc_host>:/u01/projects/MultiSolutionBundle_de.properties
$ scp /u07/retail/Bundle_as.properties rgbu_fc@<fc_host>:/u01/projects/MultiSolutionBundle_as.properties
$ scp /u07/retail/Bundle_pt.properties rgbu_fc@<fc_host>:/u01/projects/MultiSolutionBundle_pt.properties
$ scp /u07/retail/Bundle_op.properties rgbu_fc@<fc_host>:/u01/projects/MultiSolutionBundle_op.properties 我正在寻找一个解决方案,通过这个解决方案,我可以在一个scp命令中实现上述4个文件。
发布于 2017-01-13 11:15:12
使用GNU tar、ssh和bash:
tar -C /u07/retail/ -c Bundle_{de,as,pt,op}.properties | ssh user@remote_host tar -C /u01/projects/ --transform 's/.*/MultiSolution\&/' --show-transformed-names -xv如果您想在文件名中使用globbing (*):
cd /u07/retail/ && tar -c Bundle_*.properties | ssh user@remote_host tar -C /u01/projects/ --transform 's/.*/MultiSolution\&/' --show-transformed-names -xv
-C:切换到目录-c:创建一个新的存档Bundle_{de,as,pt,op}.properties:bash在执行tar命令之前将其扩展为Bundle_de.properties Bundle_as.properties Bundle_pt.properties Bundle_op.properties--transform 's/.*/MultiSolution\&/':将MultiSolution添加到文件名中--show-transformed-names:转换后显示文件名-xv:解压缩文件并逐字列出已处理的文件
发布于 2017-01-13 11:00:33
在任何标准的POSIX shell中,看起来都是一个简单的循环:
for i in de as pt op
do scp "/u07/retail/Bundle_$i.properties" "rgbu_fc@<fc_host>:/u01/projects/MultiSolutionBundle_$i.properties"
done或者,您可以在本地为文件指定新名称(复制、链接或移动),然后使用通配符传输它们:
dir=$(mktemp -d)
for i in de as pt op
do cp "/u07/retail/Bundle_$i.properties" "$dir/MultiSolutionBundle_$i.properties"
done
scp "$dir"/* "rgbu_fc@<fc_host>:/u01/projects/"
rm -rf "$dir"https://stackoverflow.com/questions/41632945
复制相似问题