Command
aws s3 rm s3://my-bucket/file.txtExplanation
Deletes files, folders, or entire directories from S3. Use `--recursive` to delete all contents under a prefix.
Common Use Cases
- •Cleaning up test data
- •Removing outdated backups
- •Deleting objects in bulk
Best Practices
- ✓Double-check paths before running recursive delete
- ✓Use versioning or object lock for protection
Common Mistakes to Avoid
- ⚠Using `--recursive` accidentally and deleting entire bucket contents
- ⚠Missing permissions (`s3:DeleteObject`)
Troubleshooting
Problem: Access denied
Solution: Ensure IAM policy allows `s3:DeleteObject`.
Problem: Partial deletion
Solution: Check object ownership and encryption policies.
Examples
Delete a single file
aws s3 rm s3://my-bucket/file.txtDelete all objects in a bucket recursively
aws s3 rm s3://my-bucket/ --recursive