CLI
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:
Terminal window npx wrangler login -
Create a bucket named
my-bucket:Terminal window npx wrangler r2 bucket create my-bucketIf prompted, select the account you want to create the bucket in.
-
Verify the bucket was created:
Terminal window 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.
- In the Cloudflare dashboard, go to R2.
- Select Manage R2 API tokens.
- Select Create API token.
- Choose Object Read & Write permission and select the buckets you want to access.
- Select Create API Token.
- Copy the Access Key ID and Secret Access Key. Store these securely — you cannot view the secret again.
Wrangler is the Cloudflare Workers CLI. It authenticates with your Cloudflare account directly, so no API credentials needed.
-
Install Wrangler:
Terminal window npm i -D wranglerTerminal window yarn add -D wranglerTerminal window pnpm add -D wrangler -
Log in to your Cloudflare account:
Terminal window wrangler login
rclone is ideal for bulk uploads, migrations, and syncing directories.
-
Install rclone ↗ (version 1.59 or later).
-
Configure a new remote:
Terminal window 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:
Terminal window aws configure -
When prompted, enter:
- AWS Access Key ID: Your R2 Access Key ID
- AWS Secret Access Key: Your R2 Secret Access Key
- Default region name:
auto - Default output format:
json(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-bucketwrangler r2 object put my-bucket/myfile.txt --file ./myfile.txt
# Download myfile.txt and save it as downloaded.txtwrangler r2 object get my-bucket/myfile.txt --file ./downloaded.txt
# List all objects in my-bucketwrangler r2 object list my-bucketRefer to the Wrangler R2 commands for all available operations.
# Upload myfile.txt to my-bucketrclone copy myfile.txt r2:my-bucket/
# Download myfile.txt from my-bucket to the current directoryrclone copy r2:my-bucket/myfile.txt .Refer to the rclone documentation for more configuration options.
# Upload myfile.txt to my-bucketaws s3 cp myfile.txt s3://my-bucket/ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
# Download myfile.txt from my-bucket to current directoryaws s3 cp s3://my-bucket/myfile.txt ./ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
# List all objects in my-bucketaws s3 ls s3://my-bucket/ --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.comRefer to the AWS CLI documentation for more examples.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2026 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-