递归使用scp,但不包括某些文件夹 [英] recursively use scp but excluding some folders

查看:47
本文介绍了递归使用scp,但不包括某些文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有些文件夹具有这些结构

Assume there are some folders with these structures

/bench1/1cpu/p_0/image/
/bench1/1cpu/p_0/fl_1/
/bench1/1cpu/p_0/fl_1/
/bench1/1cpu/p_0/fl_1/
/bench1/1cpu/p_0/fl_1/
/bench1/1cpu/p_1/image/
/bench1/1cpu/p_1/fl_1/
/bench1/1cpu/p_1/fl_1/
/bench1/1cpu/p_1/fl_1/
/bench1/1cpu/p_1/fl_1/
/bench1/2cpu/p_0/image/
/bench1/2cpu/p_0/fl_1/
/bench1/2cpu/p_0/fl_1/
/bench1/2cpu/p_0/fl_1/
/bench1/2cpu/p_0/fl_1/
/bench1/2cpu/p_1/image/
/bench1/2cpu/p_1/fl_1/
/bench1/2cpu/p_1/fl_1/
/bench1/2cpu/p_1/fl_1/
/bench1/2cpu/p_1/fl_1/
....

我想做的是 scp 以下文件夹

/bench1/1cpu/p_0/image/
/bench1/1cpu/p_1/image/
/bench1/2cpu/p_0/image/
/bench1/2cpu/p_1/image/

如您所见,我想递归使用 scp ,但不包括所有名为"fl_X"的文件夹.看来scp没有这样的选择.

As you can see I want to recursively use scp but excluding all folders that name "fl_X". It seems that scp has not such option.

更新scp没有这种功能.相反,我使用以下命令

UPDATE scp has not such feature. Instead I use the following command

 rsync -av --exclude 'fl_*' user@server:/my/dir

但是它不起作用.它只传输文件夹列表!类似于 ls -R

But it doesn't work. It only transfers the list of folders!! something like ls -R

推荐答案

尽管 scp 支持使用 -r 选项进行递归目录复制,但它不支持过滤文件.有几种方法可以完成您的任务,但是我可能会依赖 find xargs tar ssh 而不是 scp .

Although scp supports recursive directory copying with the -r option, it does not support filtering of the files. There are several ways to accomplish your task, but I would probably rely on find, xargs, tar, and ssh instead of scp.

find . -type d -wholename '*bench*/image' \
| xargs tar cf - \
| ssh user@remote tar xf - -C /my/dir

可以使 rsync 解决方案起作用,但是您缺少一些参数. rsync 还需要 r 开关才能递归到子目录中.另外,如果您想要与 scp 相同的安全性,则需要在 ssh 下进行传输.像这样:

The rsync solution can be made to work, but you are missing some arguments. rsync also needs the r switch to recurse into subdirectories. Also, if you want the same security of scp, you need to do the transfer under ssh. Something like:

rsync -avr -e "ssh -l user" --exclude 'fl_*' ./bench* remote:/my/dir

这篇关于递归使用scp,但不包括某些文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆