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

npminstall-gnetlify-cli

2. Login

netlifylogin

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

3. Get Site List

netlifysites:list

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

netlifysites:list-json

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

nispf"emirotptirloenirstinuuspppft(,arpirrry=fmldtiiij'seaennnssjT=t_tttiosoi=ei(((tnotnsddfffe,nas.'''s.le.g=={:sl:ngeilyouetss+isa{mt(..1sdle('gg:t(er'uee3UUsnanrttdRpy(tal((}Ld-ssem'''.:aj.i(e,uitssts'pd{{eotei,'d'nudndstNa,ar:i)e'/tml|n}sNAe'e}{))/'dN}'ups:A)_/')pyi'aA)dtt)t'ahe')tos,en\d3n'}'N-)/cAI'D"):[:{1s0i]te_id}')

4. Delete a Site

To delete individually:

netlifysites: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.

#sdffdeeee!ieaoocccc/t"""lirineiefnhhhhbexyzeldacflieooooisxyztee=mhesen=xyzedn"eonc(ec(""""/(xyzd=t$=ehdhf"=SFbxyz=0r{"-toeoa=uaaxyz0ye$nlli=cisxyzn{i"e"lclhxyzite"fOtFeCee---nrnDyKeAdosdxyzyte"dI+ms:xyz"%rls+L+pfxyz$%yei+E)lu$xyz{:#tt)D)elf---s*#ie)"tlaxyzi}*nseyixyzt":g:lxyze}:d=dexyzs"e=ed---[$l=l"xyz@ne"exyz]attxyz}meexyz"ed---;:xyz-xyzdf$xyzoodxyzrexyz"clxyzeexyztxyz"exyz$dxyzi"xyzdxyz":::sss2iii>ttt&eee1---;nnnaaatmmmheeee---n123"""

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

curhltt-pHs:"/A/uatphio.rnieztaltiifoyn.:coBme/aarpeir/v$1N/EsTiLtIeFsY_AUTH_TOKEN"\

Delete a Site

cur-hlHtt-"pXAsu:Dt/EhLaErpTiiEz.an\teitolni:fyB.ecaorme/rap$iN/EvT1L/IsFiYt_eAsU/T<Hs_iTtOeK-EiNd">\

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