且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

scp 从多个目录下载多个文件

更新时间:2023-11-10 22:21:10

您可以使用 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