2017-02-23 77 views
1

我有諸如路徑的S3桶:AWS CLI 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/ 

用單個命令?

回答

0

我想你只需要做

aws s3 cp s3://mybucket/data/ s3://mybucket/data/ --recursive --include "file_file*.txt" 

複製它

+0

謝謝你的迴應,而是給出了一個錯誤。我不認爲在路徑名中支持通配符 – Dlob

+0

是的,我意識到,在我保存後,這應該更有效 –

1

遞歸複製S3對象複製到另一個桶

當參數--recursive全部通過,下面的cp命令遞歸副本通過使用--exclude參數,將指定存儲桶下的對象轉移到另一個存儲桶,同時排除某些對象。在這個例子中,鬥mybucket有對象test1.txtanother/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 command documentation

相關問題