DEV Community

Discussion on: How to delete ALL node_modules folders on your machine and free up HD space!

Collapse
 
sebtoombs profile image
Seb

If anyone else wants to know how to delete node_modules folders that haven't been used recently, modify the find command to check the mtime (modified time) of the folder. I use this to only delete node_modules older than 30 days like so;

Delete node_modules older than 30 days;

find . -name "node_modules" -type d -prune -print -mtime +30 | xargs du -chs
Enter fullscreen mode Exit fullscreen mode

The -mtime flag can be configured other ways, e.g. to get all files modified today pass -1 instead.

Collapse
 
markpieszak profile image
Mark Pieszak

WOW I love this !!!! This is an amazing addition :)
Adding this to my bash profile immediately - this is basically what I've always needed!

Great find Seb !