Skip to content

Instantly share code, notes, and snippets.

@thelicato
Created March 18, 2022 16:48
Show Gist options
  • Save thelicato/250af2d1f505cd387ee55a1f93613cfa to your computer and use it in GitHub Desktop.
Save thelicato/250af2d1f505cd387ee55a1f93613cfa to your computer and use it in GitHub Desktop.
Delete all node_modules recursively (Linux/OS X/Windows)

Linux/OS X

Print folders

This command will print out each folder and also show how much space the folder is occupying.

find . -name "node_modules" -type d -prune -print | xargs du -chs

Delete folders

find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;

Windows

Print folders

FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" echo %d"

Delete folders (cmd)

FOR /d /r . %d in (node_modules) DO @IF EXIST "%d" rm -rf "%d"

Delete folders (PowerShell)

Get-ChildItem -Path "." -Include "node_modules" -Recurse -Directory | Remove-Item -Recurse -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment