Skip to main content

cleanup

·1 min

Often end up finding I start to run out of space on my filesystem after a few months of use so I needed to find a way to search for directories that I know I can safely delete.

For example for Node.js projects often end up with very large node_modules directory.

The following command will list all node_modules from the current directory and there size.

# List all directories named node_modules and their sizes
$ find . -name 'node_modules' -type d -prune -print | xargs du -chs

It always wroth running the command above first to confirm that all the directories it finds are correct. Once validated the directories are safe to delete the command can then be altered to delete these directories and all the files and directories under them.

# Remove all node_modules folders (from current directory down)
$ find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;

Doing this can for node_modules and other similar folders like vendor for PHP projects can help save lots of space.