How Can I Easily Delete All Files in a Bucket?

To easily delete all files in a bucket, first, install the B2 Command Line tool installed on the computer. If assistance is needed with setting up this installation, please refer to our Command Line tool documentation here


Once the Command Line tool is installed, follow these steps:

1) Open Terminal.
2) Create a new local directory (e.g., mkdir)
3) Change into that directory (e.g., cd empty)
4) Run the following command: b2 sync --delete . b2://mybucketname where mybucketname is the name of the bucket you wish to remove.

This will sync the empty contents of the local directory to the bucket.  


However, if there are still unfinished large files in the bucket, this method by itself will not remove those unfinished listings. The bucket may still report as not being fully empty.

In order to remove unfinished large files, call b2 cancel_all_unfinished_large_files mybucketname. Then, try to delete the bucket once more.



Have more questions? Submit a request


Article is closed for comments.
Powered by Zendesk