Skip to content
Cloudflare Docs

CLI

Manage R2 buckets and objects directly from your terminal. Use CLI tools to automate tasks and manage objects.

ToolBest for
WranglerSingle object operations and managing bucket settings with minimal setup
rcloneBulk object operations, migrations, and syncing directories
AWS CLIExisting AWS workflows or familiarity with AWS CLI

1. Create a bucket

A bucket stores your objects in R2. To create a new R2 bucket:

  1. Log in to your Cloudflare account:

    Terminal window
    npx wrangler login
  2. Create a bucket named my-bucket:

    Terminal window
    npx wrangler r2 bucket create my-bucket

    If prompted, select the account you want to create the bucket in.

  3. Verify the bucket was created:

    Terminal window
    npx wrangler r2 bucket list

2. Generate API credentials

CLI tools that use the S3 API (AWS CLI, rclone) require an Access Key ID and Secret Access Key. If you are using Wrangler, you can skip this step.

  1. In the Cloudflare dashboard, go to R2.
  2. Select Manage R2 API tokens.
  3. Select Create API token.
  4. Choose Object Read & Write permission and select the buckets you want to access.
  5. Select Create API Token.
  6. Copy the Access Key ID and Secret Access Key. Store these securely — you cannot view the secret again.

3. Set up a CLI tool

Wrangler is the Cloudflare Workers CLI. It authenticates with your Cloudflare account directly, so no API credentials needed.

  1. Install Wrangler:

    Terminal window
    npm i -D wrangler
  2. Log in to your Cloudflare account:

    Terminal window
    wrangler login

4. Upload and download objects

(Optional) Create a test file to upload. Run this command in the directory where you plan to run the CLI commands:

Terminal window
echo 'Hello, R2!' > myfile.txt
Terminal window
# Upload myfile.txt to my-bucket
wrangler r2 object put my-bucket/myfile.txt --file ./myfile.txt
# Download myfile.txt and save it as downloaded.txt
wrangler r2 object get my-bucket/myfile.txt --file ./downloaded.txt
# List all objects in my-bucket
wrangler r2 object list my-bucket

Refer to the Wrangler R2 commands for all available operations.

Next steps