How to create and use UDF in Spark?
June 12, 2023How to delete an index in Elasticsearch?
June 26, 2023In 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