Free up space by removing node_modules recursively

July 31, 2018

To remove all node_modules folders recursively from a directory run:

find . -name "node_modules" -exec rm -rf '{}' +

I have a few top level directories on my machine including

  • experiments
  • personal
  • work

I was able to run this command in the parent directory and reclaim space in all the sub-directories.

You can adapt this to other project types by changing node_modules to the other platforms' dependency/build folder.

For Rust:

find . -name "target" -exec rm -rf '{}' +

For Elixir:

find . -name "deps" -exec rm -rf '{}' +

Now what to do with all this space? 😄