How to delete files recursively from an S3 bucket

后端 未结 12 469
不知归路
不知归路 2021-01-29 23:54

I have the following folder structure in S3. Is there a way to recursively remove all files under a certain folder (say foo/bar1 or foo or foo/bar2/1 ..)

         


        
12条回答
  •  孤独总比滥情好
    2021-01-30 00:28

    The voted up answer is missing a step.

    Per aws s3 help:

    Currently, there is no support for the use of UNIX style wildcards in a command's path arguments. However, most commands have --exclude "" and --include "" parameters that can achieve the desired result......... When there are multiple filters, the rule is the filters that appear later in the command take precedence over filters that appear earlier in the command. For example, if the filter parameters passed to the command were --exclude "*" --include "*.txt" All files will be excluded from the command except for files ending with .txt

    aws s3 rm --recursive s3://bucket/ --exclude="*" --include="/folder_path/*" 
    

提交回复
热议问题