linode-cli
linode-cli copied to clipboard
Add support for wildcard delete all objects in a bucket or folder
Is there a way to delete all files in a bucket or at least a folder in a bucket? It doesn't seem like it.
I'd like to see support for the following usages:
The wildcard character actually takes all local files in $PWD
and passes as argument(s) to the command
$ linode-cli obj del jtara1.photos *
I don't understand why I get this error here. Q1
is a folder in the bucket containing files.
$ linode-cli obj del jtara1.photos Q1/*
S3ResponseError: 403 Forbidden
Thanks for the report!
I did some testing, and I'm also not totally sure why you get a 403 there - I can reproduce it though, so I'll look into it a bit more and report back.
For the time being, you can remove all items in a folder/bucket with a command like this:
MY_BUCKET="your-bucket-name"
PREFIX="test/" # the trailing slash is necessary
linode-cli obj ls $MY_BUCKET/$PREFIX | tr -s ' ' ' ' | cut -f4 -d ' ' | xargs -L1 -- linode-cli obj rm $MY_BUCKET/
This should be included in the next CLI release, expected this afternoon
I found this way of deleting a folder
linode-cli obj rb $bucket/$folder
The above PR also allowed linode-cli obj rb --recursive $bucket/$folder
to accomplish this. Looks like I forgot to close this issue when it shipped, but it's been in the CLI since 5.4.0