Reputation: 643
Is it possible to delete multiple subfolders in S3 using the AWS CLI? There's include and exclude
command specified in the documentation but I think it's for the S3 Items and not for folders?
Tried this command but its not working aws s3 rm s3://bucketname/*/*/foldertodelete --recursive
Sample folder structure:
bucketname/folder/subfolder/itemfolder
bucketname/folder/subfolder/foldertodelete
bucketname/anotherfolder/subfolder/itemfolder
bucketname/anotherfolder/subfolder/foldertodelete
bucketname/andanotherfolder/andsubfolder/itemfolder
bucketname/andanotherfolder/andsubfolder/foldertodelete
Did I missed something? Any help would be appreciated. Thanks
Upvotes: 0
Views: 3171
Reputation: 5828
You could use multiple --include
s:
aws s3 rm s3://bucket --recursive --include "folder1/*" --include "foo/folder2/*"
...as well as multiple --exclude
s.
Note: the order of --include
and --exclude
matters, they are applied in order. Also default is --include "*"
if nothing given.
Upvotes: 0
Reputation: 3992
Try this: (Make sure you create a backup before running the command to avoid any unexpected result)
aws s3 rm s3://bucketname/ --exclude "*" --include "*foldertodelete/*" --recursive
Wildcard is not supported in the command's path argument.
Upvotes: 6