Recursively remove all "node_modules" folders

find . -name node_modules -exec rm -rf {} +

March 29, 2020tg-z

Explanation

Beware: this removes folders without confirmation. Use only if necessary!

To make the command ask for confirmation before deleting folders, simply add the -i flag for the rm command: rm -rfi.

  • The find command finds files and folders matching conditions.
  • . is the target folder to search in: the current folder
  • -name node_modules will match files or folders with the exact name "node_modules"
  • -exec ... {} + executes some command, replacing the {} with as many path names as possible for the executed command (in this example rm -fr)