How To Delete Data with AWS CLI

Learn how to delete large amounts of objects or specific groups of objects from Filebase buckets using AWS CLI

The Filebase web dashboard supports deleting up to 1,000 objects at one time. In some situations, it may be tedious and time consuming to delete 1,000 objects at a time. The web dashboard also supports emptying an entire bucket. While this might be the fastest solution in some situations, others may require only certain files be deleted, not just everything within a bucket.

This guide will showcase how to use AWS CLI for a more efficient method to delete all objects in a bucket from the command line and how to delete a large amount of specific objects.

Prerequisites:

Deleting All Objects In A Bucket

To delete all objects in a bucket, use the aws --endpoint https://s3.filebase.com s3 rm --recursive s3://bucket_name/ command. For example, to delete all objects from the bucket 'filebase-bucket':

aws --endpoint https://s3.filebase.com s3 rm --recursive s3://filebase-bucket/

Deleting groups of specific objects in a bucket

To delete objects that match specific naming conventions, you can use the --exclude or --include flags with the aws --endpoint https://s3.filebase.com s3 rm s3://bucket_name/ command. These flags are followed by patterns that the object names will need to match to either be included or excluded from the delete command.

The following character patterns are supported to be used with the --exclude and --include flags.

  • * : Matches everything

  • ? : Matches any single character

  • [sequence] : Matches any character in sequence

  • [!sequence] : Matches any character not in sequence

For example, to delete all files that end with “.jpg”, you can use the command:

aws --endpoint https://s3.filebase.com s3 rm --include “*.jpg” s3://filebase-bucket

To delete all files except those that end with “.txt”, you can use the command:

aws --endpoint https://s3.filebase.com s3 rm --exclude “*.txt” s3://filebase-bucket

If you have any questions, please join our Discord server, or send us an email at hello@filebase.com

Last updated