aws-s3-rm
Remove objects from Amazon S3 buckets
TLDR
Delete a specific S3 object
Preview the deletion of a specific S3 object without deleting it (dry-run)
Delete an object from a specific S3 access point
Remove all objects from a bucket (empty the bucket)
Display help
SYNOPSIS
aws s3 rm s3://bucket[/prefix] [--recursive] [--exclude "pattern"] [--include "pattern"] [--dryrun]
PARAMETERS
--recursive
Recursively delete all objects under the specified prefix or bucket.
--exclude
Exclude files/objects matching the glob pattern from deletion (can repeat).
--include
Include files/objects matching the glob pattern (overrides prior excludes; must follow --exclude).
--dryrun
Show what would be deleted without actually performing the operation.
DESCRIPTION
The aws s3 rm command is part of the AWS Command Line Interface (CLI) for managing Amazon S3 storage. It removes specified objects or all objects under a prefix from an S3 bucket.
Unlike the low-level aws s3api delete-object, this high-level command supports recursive deletion, pattern-based inclusion/exclusion, and dry-run previews, making bulk operations efficient.
Specify targets using S3 URIs like s3://my-bucket/my-key.txt. For directories or prefixes, use --recursive to delete everything matching the path. Patterns with --exclude and --include allow fine-grained control, processed left-to-right.
This command permanently deletes objects unless S3 bucket versioning is enabled, in which case delete markers are created. Always verify with --dryrun for large deletions to avoid data loss. It streams progress for large operations and integrates with AWS credentials for secure access.
CAVEATS
Deletions are irreversible without versioning; recursive ops can delete millions of objects—use --dryrun first. No confirmation prompts. Patterns are glob-style, not regex. Fails if lacking s3:DeleteObject permissions.
EXAMPLES
Single object: aws s3 rm s3://bucket/key.txt
Recursive bucket empty: aws s3 rm s3://bucket/ --recursive
Exclude logs: aws s3 rm s3://bucket/ --recursive --exclude '*.log'
EXIT CODES
0: Success
1: General error (permissions, network, invalid args)
2: Mismatched command usage
HISTORY
Introduced in AWS CLI v2 (2019) as high-level S3 command for streamlined operations, replacing verbose low-level API calls from v1.


