user2803194
user2803194

Reputation: 105

Deleting files from s3 of 0 bytes

Is there a way to delete files of 0bytes from amazon s3 bucket. I am currently trying out

aws s3 ls s3//bucket --recursive --profile ***** | awk '{ seq_no = $3; if ( seq_no == 0) print "rm s3://bucket/" $4; }' | sh

but this does not work.

Is there any other way to do this

Thanks

Upvotes: 1

Views: 2678

Answers (1)

varun r
varun r

Reputation: 204

You may use :

s3cmd ls --recursive s3://BUCKET_NAME | ruby -rdate -ne 'date, time, size, uri = $_.split; puts uri if size == "0"' | xargs s3cmd del

if you don't have s3cmd installed, aws s3 ls works as well.

Reference: https://gist.github.com/fernandoaleman/4551494

UPDATE :

To be exact

for filename in `aws s3 ls --recursive s3://$BUCKETNAME/$FOLDERLOCATION/| ruby -rdate -ne 'date, time, size, uri = $_.split; puts uri if size == "0"'` do aws s3 rm s3://$BUCKETNAME/$filename done

this worked for me.

Upvotes: 1

Related Questions