首页 > 解决方案 > 使用 aws 客户端仅从单个目录复制 s3 文件(非递归)

问题描述

考虑沿这些线的 aws 存储桶/键结构

 myBucket/dir1/file1
 myBucket/dir1/file2
 myBucket/dir1/dir2/dir2file1
 myBucket/dir1/dir2/dir2file2

使用时:

 aws s3 cp  --recursive s3://myBucket/dir1/ .

dir2file[1,2]然后我们将一起复制下来file[1,2]。如何只复制后面的文件而不是子目录下的文件?

回复评论:。我对--exclude为每个子目录放置一个不感兴趣,所以这不是从 aws cp 中排除目录的重复

标签: amazon-web-servicesamazon-s3aws-sdkaws-cli

解决方案


您可以使用该选项排除路径--exclude,例如

aws s3 cp s3://myBucket/dir1/ . --recursive --exclude "dir1/dir2/*"

使用 aws cli 帮助可以找到更多选项和示例

aws s3 cp help

推荐阅读