Remove node_modules recursively

Save your space, remove your node_modules now!

Here is syntax to remove node_module recursively at root of folder:

find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +


Explaination:

find: This is the command used to search for files and directories within a specified directory hierarchy.

.: This represents the starting directory for the search. In this case, it's the current directory (denoted by .).

-name 'node_modules': This specifies the name of the directory to search for. In this case, it's looking for directories named "node_modules".

-type d: This flag tells find to only consider directories.

-prune: This option tells find to not descend into directories that match the specified criteria. So, when it finds a directory named "node_modules", it won't search within that directory.

-exec rm -rf '{}' +: This is the action to take for each found directory. It executes the rm -rf command on the found directories. rm is the command to remove files or directories, -rf are options to recursively force removal without prompting for confirmation, and {} represents the placeholder for the found directories. The + at the end is used to indicate the end of the command to execute.

Original article: stackoveflow