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
2. 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
To get the list in JSON format, add the --json option.
Formatting with Python or similar tools makes it easier to review.
4. Delete a Site
To delete individually:
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.
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
Delete a Site
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:listandsites:delete - The
--jsonoption makes it easy to process programmatically - The
--forceoption skips confirmation prompts, making it convenient for bulk processing - Deletions are irreversible, so always review the site list before executing