Skip to content

Instantly share code, notes, and snippets.

@willianfalbo
Last active March 6, 2023 17:02
Show Gist options
  • Save willianfalbo/ab915ec145111e6661201b7b97ada25a to your computer and use it in GitHub Desktop.
Save willianfalbo/ab915ec145111e6661201b7b97ada25a to your computer and use it in GitHub Desktop.
Delete node_modules folder recursively from a specified path using command line

Print out a list of directories to be deleted:

find . -name 'node_modules' -type d -prune

Delete directories from the current working directory:

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

Alternatively you can use trash (brew install trash) for staged deletion:

find . -name node_modules -type d -prune -exec trash {} +

Reference: https://stackoverflow.com/a/43561012/11644167

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