How to search for node_modules and delete all in a path

$ find path -name “node_modules” -type d -exec rm -rf {} +

Ion Utale
2 min readOct 1, 2023

Node modules are essential for developing JavaScript applications. However, they can also take up a lot of disk space, especially if you have multiple projects. In this article, we will show you how to search for and delete all node_modules folders in a path, using a simple command line command.

Why delete node_modules folders?

There are a few reasons why you might want to delete node_modules folders:

  • To free up disk space
  • To remove unused dependencies
  • To avoid conflicts between different versions of the same dependency

How to search for and delete all node_modules folders in a path

To search for and delete all node_modules folders in a path, you can use the following command:

find path -name "node_modules" -type d -exec rm -rf {} +

This command will first use the find command to search the specified path for all folders named node_modules. It will then use the -type d option to filter the results to only include directories. Finally, it will use the -exec option…

--

--

Ion Utale
Ion Utale

No responses yet