scp 来自源和目标的不同名称的多个文件

scp multiple files with different names from source and destination

我正在尝试将多个文件从源 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 个文件。

在任何标准中看起来都是一个简单的循环 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

或者,您可以在本地为文件命名(复制、link 或移动),然后使用通配符传输它们:

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"

使用 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: change to directory

-c: create a new archive

Bundle_{de,as,pt,op}.properties: bash is expanding this to Bundle_de.properties Bundle_as.properties Bundle_pt.properties Bundle_op.properties before executing tar command

--transform 's/.*/MultiSolution\&/': prepend MultiSolution to filenames

--show-transformed-names: show filenames after transformation

-xv: extract files and verbosely list files processed