| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/r2/get-started/cli/ | [Back] [Original] |
Manage R2 buckets and objects directly from your terminal. Use CLI tools to automate tasks and manage objects.
| Tool | Best for |
|---|---|
| Wrangler | Single object operations and managing bucket settings with minimal setup |
| rclone | Bulk object operations, migrations, and syncing directories |
| AWS CLI | Existing AWS workflows or familiarity with AWS CLI |
A bucket stores your objects in R2. To create a new R2 bucket:
Log in to your Cloudflare account:
npx wrangler login
Create a bucket named my-bucket:
npx wrangler r2 bucket create my-bucket
If prompted, select the account you want to create the bucket in.
Verify the bucket was created:
npx wrangler r2 bucket list
In the Cloudflare Dashboard, go to R2 object storage.
Go to Overview ↗Select Create bucket.
Enter a name for your bucket.
Select a location for your bucket and a default storage class.
Select Create bucket.
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.
Wrangler is the Cloudflare Workers CLI. It authenticates with your Cloudflare account directly, so no API credentials needed.
Install Wrangler:
npm i -D wrangleryarn add -D wranglerpnpm add -D wranglerbun add -d wranglerLog in to your Cloudflare account:
wrangler login
rclone is ideal for bulk uploads, migrations, and syncing directories.
Install rclone (version 1.59 or later).
Configure a new remote:
rclone config
Create new remote by selecting n.
Name your remote r2
Select Amazon S3 Compliant Storage Providers as the storage type.
Select Cloudflare R2 as the provider.
Select whether you would like to enter AWS credentials manually, or get it from the runtime environment.
Enter your Access Key ID and Secret Access Key when prompted.
Select the region to connect to (optional).
Provide your S3 API endpoint.
The AWS CLI works with R2 by specifying a custom endpoint.
Install the AWS CLI for your operating system.
Configure your credentials:
aws configure
When prompted, enter:
autojson (or press Enter to skip)(Optional) Create a test file to upload. Run this command in the directory where you plan to run the CLI commands:
echo 'Hello, R2!' > myfile.txt
# 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.txtRefer to the Wrangler R2 commands for all available operations.
# Upload myfile.txt to my-bucket
rclone copy myfile.txt r2:my-bucket/
# Download myfile.txt from my-bucket to the current directory
rclone copy r2:my-bucket/myfile.txt .Refer to the rclone documentation for more configuration options.
# Upload myfile.txt to my-bucket
aws s3 cp myfile.txt s3://my-bucket/ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
# Download myfile.txt from my-bucket to current directory
aws s3 cp s3://my-bucket/myfile.txt ./ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
# List all objects in my-bucket
aws s3 ls s3://my-bucket/ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.comRefer to the AWS CLI documentation for more examples.
| Web Proxy Viewer | New URL | Original Page |