How to recursively delete files, folders or bucket from S3? - Big Data In Real World

How to recursively delete files, folders or bucket from S3?

How to create and use UDF in Spark?
June 12, 2023
How to delete an index in Elasticsearch?
June 26, 2023
How to create and use UDF in Spark?
June 12, 2023
How to delete an index in Elasticsearch?
June 26, 2023

In this post we will see how to recursively delete files/objects, folders and bucket from S3.

Recursively deleting a folder in S3

rm –recursive followed by the bucketname and directory will do the job.

[osboxes@wk1 ~]$ aws s3 ls s3://hirw-sample-aws-bucket
                           PRE dist/
2020-11-18 18:15:50       1465 README.md
2020-11-18 18:16:08      68271 THIRD_PARTY_LICENSES
2020-11-18 18:17:37       4047 install

[osboxes@wk1 ~]$ aws s3 rm --recursive s3://hirw-sample-aws-bucket/dist

----
----

delete: s3://hirw-sample-aws-bucket/dist/docutils/writers/s5_html/themes/small-black/__base__
delete: s3://hirw-sample-aws-bucket/dist/docutils/writers/s5_html/themes/small-black/pretty.css
delete: s3://hirw-sample-aws-bucket/dist/docutils/writers/s5_html/themes/small-white/framing.css
delete: s3://hirw-sample-aws-bucket/dist/docutils/writers/s5_html/themes/small-white/pretty.css
delete: s3://hirw-sample-aws-bucket/dist/include/python3.7m/pyconfig.h
delete: s3://hirw-sample-aws-bucket/dist/fcntl.cpython-37m-x86_64-linux-gnu.so
delete: s3://hirw-sample-aws-bucket/dist/grp.cpython-37m-x86_64-linux-gnu.so
delete: s3://hirw-sample-aws-bucket/dist/libbz2.so.1
delete: s3://hirw-sample-aws-bucket/dist/lib/python3.7/config-3.7m-x86_64-linux-gnu/Makefile
delete: s3://hirw-sample-aws-bucket/dist/libffi.so.5

----
----

[osboxes@wk1 ~]$ aws s3 ls s3://hirw-sample-aws-bucket
2020-11-18 18:15:50       1465 README.md
2020-11-18 18:16:08      68271 THIRD_PARTY_LICENSES
2020-11-18 18:17:37       4047 install

Recursively delete all objects from the bucket

 rm –recursive followed by just the bucket name will remove all objects under the bucket.

[osboxes@wk1 ~]$ aws s3 rm --recursive s3://hirw-sample-aws-bucket
delete: s3://hirw-sample-aws-bucket/install
delete: s3://hirw-sample-aws-bucket/THIRD_PARTY_LICENSES
delete: s3://hirw-sample-aws-bucket/README.md

Deleting the bucket from S3

rb command will delete the bucket from S3.

[osboxes@wk1 ~]$ aws s3 rb s3://hirw-sample-aws-bucket
remove_bucket: hirw-sample-aws-bucket
Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.

Comments are closed.

How to recursively delete files, folders or bucket from S3?
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X