linode-cli icon indicating copy to clipboard operation
linode-cli copied to clipboard

Add support for wildcard delete all objects in a bucket or folder

Open jtara1 opened this issue 3 years ago • 2 comments

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

jtara1 avatar Mar 09 '21 21:03 jtara1

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/

Dorthu avatar Mar 10 '21 12:03 Dorthu

This should be included in the next CLI release, expected this afternoon

Dorthu avatar May 17 '21 15:05 Dorthu

I found this way of deleting a folder

linode-cli obj rb $bucket/$folder

escaper01 avatar Aug 25 '22 14:08 escaper01

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

Dorthu avatar Aug 29 '22 12:08 Dorthu