9

http://docs.aws.amazon.com/cli/latest/reference/s3/rm.html

s3://foo/2015-01-01/..
s3://foo/2015-01-02/..
s3://foo/2015-01-03/..
..
s3://foo/2016-01-01/..
s3://foo/2016-01-02/..
s3://foo/2016-01-03/..

In the above setup, I would like to apply wild card on my removals.

e.g. aws s3 rm s3://foo/2015* 
or
aws s3 rm s3://foo/2016-02-* 

I am unable to achieve this with the existing command, is it achievable since I have large number of files to delete and I would like to run commands in parallel for faster deletes.

1
  • I have no access to my aws account from there but aws s3 rm s3://foo/201{5..6}-{01..08}-{01..03} --recursive (recursive to delete content of the bucket) Commented Aug 2, 2016 at 11:17

2 Answers 2

19

Currently, there is no support for the use of UNIX style wildcards in a command's path arguments, but you can use --exclude "<value>" and --include "<value>" parameters that can achieve the desired result:

aws s3 rm s3://foo/ --recursive --exclude "*" --include "2016-02-*" --dryrun
1
  • 6
    This does not make any difference between files and folders, nice addition of --dryrun !
    – Luke
    Commented Dec 12, 2019 at 11:34
3

You cannot use Unix-style wildcards in the path but you can use filters on the S3 rm request to replicate the wildcard functionality. (See http://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters for examples.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.