I had accumulated a large number of Netlify sites, so here is a summary of the steps I took to bulk delete them using the CLI.

Background

The number of Netlify sites created during development and testing had grown to 41. Since only a few sites were currently in use, I decided to delete the old sites in bulk.

Environment

  • macOS
  • Node.js
  • netlify-cli v23.15.1

Steps

1. Install Netlify CLI

npm install -g netlify-cli

2. Login

netlify login

A browser will open and display the Netlify authentication screen. After authorizing, the token will be saved to the CLI.

3. Get Site List

netlify sites:list

To get the list in JSON format, add the --json option.

netlify sites:list --json

Formatting with Python or similar tools makes it easier to review.

netlify sites:list --json | python3 -c "
import json, sys
sites = json.load(sys.stdin)
print(f'Total: {len(sites)} sites\n')
for i, s in enumerate(sites):
    name = s.get('name', 'N/A')
    url = s.get('url', 'N/A')
    updated = s.get('updated_at', 'N/A')[:10]
    site_id = s.get('id', 'N/A')
    print(f'{i+1:3d}. {name}')
    print(f'     URL: {url}')
    print(f'     Updated: {updated}  ID: {site_id}')
"

4. Delete a Site

To delete individually:

netlify sites:delete --force <site-id>

Without --force, a confirmation prompt will be displayed.

5. Bulk Delete with Shell Script

You can put the site IDs and names of deletion targets into an array and delete them in a loop.

#!/bin/bash

sites=(
  "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:site-name-1"
  "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy:site-name-2"
  "zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz:site-name-3"
)

deleted=0
failed=0

for entry in "${sites[@]}"; do
  id="${entry%%:*}"
  name="${entry##*:}"
  echo -n "Deleting: $name ... "
  if netlify sites:delete --force "$id" 2>&1; then
    echo "OK"
    ((deleted++))
  else
    echo "FAILED"
    ((failed++))
  fi
done

echo ""
echo "=== Complete ==="
echo "Successfully deleted: $deleted"
echo "Failed: $failed"

Using the API Directly

It is also possible to call the REST API directly without using the CLI.

Obtaining an Authentication Token

Create a token from Netlify User Settings > Applications > Personal access tokens.

Get Site List

curl -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
  https://api.netlify.com/api/v1/sites

Delete a Site

curl -X DELETE \
  -H "Authorization: Bearer $NETLIFY_AUTH_TOKEN" \
  https://api.netlify.com/api/v1/sites/<site-id>

Results

This time, 39 out of 41 sites were deleted, leaving only the 2 sites currently in use. All deletions completed without errors.

Summary

  • Site management is easy with Netlify CLI’s sites:list and sites:delete
  • The --json option makes it easy to process programmatically
  • The --force option skips confirmation prompts, making it convenient for bulk processing
  • Deletions are irreversible, so always review the site list before executing