gpt4 book ai didi

linux - 根据文件名条件复制文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:05:42 25 4
gpt4 key购买 nike

仅当文件名包含我的 file.txt 文件中的任何名称时,才从远程复制所有文件。

file.txt 包含如下名称

rahul
jon
babra

目前我正在这样做:

while read p; do      
scp -i somefile.pem myuser@myip:myfolder/\*$p\* .
done<file.txt

但这会为我的 file.txt 中的每个名称打开到远程的连接。

我正在寻找一种优化方式,以便在单个连接中提供所有文件?

最佳答案

打开一个主连接,每个后续 scp 都可以重用。请参阅 man ssh_config 中的各种 Control* 选项,以获取有关使用更安全的控制路径的建议。

# Don't run a command (-N), but open a reusable connection (-M and -S)
# then go to the background (-f)
ssh -fNM myuser@myip -S "%C"

while read p; do
# Reuse the open connection (-S)
scp -i somefile.pem -S "%C" myuser@myip:myfolder/\*$p\* .
done < file.txt

# Close the background connection
ssh -S "%C" -O exit

关于linux - 根据文件名条件复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42069749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com