Remove all node_module folders recursively
Remove all node_module folders (or any type of folder/file)
find . -name "node_modules" -type d -exec rm -rf '{}' +
That will delete the folder and files even if there is a space in the name.
That saved me about 5GB over several hundred node projects which I had not touched in a while.
If I need the node modules back, I can simply run npm install
Written by S.Lacy
Related protips
3 Responses
This helped me, thanks man :)
Don't you think adding -type d
to the find command might improve it a little, so it would be
find . -name "node_modules" -type d -exec rm -rf '{}' +
Include the "prune" argument to not go over children nodemodules.
```
find . -name "nodemodules" -type d -prune -exec rm -rf '{}' +
```
I created an Automator action that searches my /Sites
folder for node_module
folders and autmagically moves them to the Trash on my Mac. I have my /Documents
folder and /Sites
folders symlinked with my /Dropbox
folder so they are backed up automatically. In the event I have have a full system crash and no current backup it works out great.