How to delete files recursively from an S3 bucket

后端 未结 12 486
不知归路
不知归路 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:23

    With the latest aws-cli python command line tools, to recursively delete all the files under a folder in a bucket is just:

    aws s3 rm --recursive s3://your_bucket_name/foo/
    

    Or delete everything under the bucket:

    aws s3 rm --recursive s3://your_bucket_name
    

    If what you want is to actually delete the bucket, there is one-step shortcut:

    aws s3 rb --force s3://your_bucket_name
    

    which will remove the contents in that bucket recursively then delete the bucket.

    Note: the s3:// protocol prefix is required for these commands to work

提交回复
热议问题