Skip to content

Instantly share code, notes, and snippets.

@martin-cotta
Created February 13, 2021 20:11
Show Gist options
  • Save martin-cotta/1ff67a283b20bb04b936d40507b15ebb to your computer and use it in GitHub Desktop.
Save martin-cotta/1ff67a283b20bb04b936d40507b15ebb to your computer and use it in GitHub Desktop.
Delete node_modules folders recursively

Delete node_modules recursively

cd directory-to-prune

# delete all node_modules in a single rm command
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +

# or delete folders one by one printing the folder being deleted
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;

-prune will prevent find to recurse into node_module directories (to look for nested node_modules)
{} is a placeholder which find replaces with the file path it found.
+ tells find to append all the file paths to a single command rather than running rm for each.

Interactive mode

https://github.com/voidcosmos/npkill

cd directory-to-prune

npx npkill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment