我有一个带有:
的路径的S3桶s3://mybucket/data/2017-01-01/raw/file_file1.txt
s3://mybucket/data/2017-01-01/raw/file_file2.txt
s3://mybucket/data/2017-01-01/filtered/file_file3.txt
s3://mybucket/data/2017-02-01/edited/file_file4.txt
是否有一种方法可以将目录末尾的所有文件(它们都以file_
开头)移动到:
s3://mybucket/data/
使用一个命令?
递归将S3对象复制到另一个桶
使用参数--recursive
传递时,以下cp
命令将指定存储桶下的所有对象递归到另一个存储桶中,同时使用--exclude
参数排除某些对象。在此示例中,铲斗mybucket
具有对象test1.txt
和another/test1.txt
:
aws s3 cp s3://mybucket/ s3://mybucket2/ --recursive --exclude "mybucket/another/*"
输出:
copy: s3://mybucket/test1.txt to s3://mybucket2/test1.txt
您可以组合--exclude
和--include
选项,仅复制匹配图案的对象,不包括所有其他对象:
aws s3 cp s3://mybucket/logs/ s3://mybucket2/logs/ --recursive --exclude "*" --include "*.log"
输出:
copy: s3://mybucket/test/test.log to s3://mybucket2/test/test.log
copy: s3://mybucket/test3.log to s3://mybucket2/test3.log
在您的情况下是:
aws s3 cp s3://mybucket/data/ s3://mybucket/data/ --recursive --exclude "*" --include "file_*.txt"
来源:AWS CLI cp
命令文档
我认为您只需要做
aws s3 cp s3://mybucket/data/ s3://mybucket/data/ --recursive --include "file_file*.txt"
复制