scp 从多个目录下载多个文件 [英] scp download multiple files from multiple directories

查看:212
本文介绍了scp 从多个目录下载多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用 linux 工作.我想弄清楚如何使用 scp 在多个目录中下载具有相同扩展名的多个文件.

first time I am using linux for work. I am trying to figure out how I can download multiple files with the same extension in multiple directories using scp.

例如:

/server/directoryA/directoryA1/nameA.txt
/server/directoryA/directoryA2/contactA.txt
/server/directoryA/directoryB1/nameB.txt
/server/directoryB/directoryB2/contactB.txt

我想在一个 scp 命令中下载所有 *.txt 文件.我似乎无法让它工作.

I want to download all the *.txt file in one scp command. I can't seem to get it working.

我尝试了类似的东西:

scp user@server:/server/*/*/*.txt .

我也尝试过 -r 但似乎不起作用.任何人都可以指出我正确的命令语法吗?谢谢!

I tried with -r too but doesn't seem to be working. Anyone can point me to the right command syntax? Thank you!

推荐答案

您可以使用 ssh 而不是 scp:

You can do this using ssh instead of scp:

ssh user@server 'find /server/ -name "*.txt" -print0 | xargs -0 tar -cO' | tar -xivf - -C .

这会将所有 *.txt 复制到当前目录."中,但它也会复制目录结构,因此如果您只想要没有目录结构的 txt 文件,则需要移动所有下载的 txt 文件进入当前目录:

this will copy all the *.txt into the current dir ".", but it will copy the directory structure too, so if you want just the txt files without the directory structure you will need to move all the downloaded txt files into the current directory by:

find -name "*.txt" -print0 | xargs -0 -I {} cp {} .

然后删除空目录结构:

rm ./server -r

这篇关于scp 从多个目录下载多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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