12

I am a web developer. I checkout many OSS projects and build them. Node modules are notorious in creating too many small files. I am running out of free iNodes because of that. I want an easy way (in linux) to lookup for all node_modules and delete unwanted ones. I am using the below command to list all node_modules directory and then delete them manually.

find ~/projects -name node_modules -prune

Is there a first-class utility that provides better way to manage node_modules?

Varunkumar Nagarajan
  • 1,640
  • 1
  • 26
  • 42

1 Answers1

27

Just use this: find . -name "node_modules" -prune -exec rm -rf '{}' +

NightOwl888
  • 53,678
  • 21
  • 130
  • 204
BILL
  • 4,491
  • 10
  • 55
  • 92
  • What ending sign "+" do in expression above? I don't see this syntax before. Anyway thank you, command works nice. – Bacher Jan 09 '20 at 09:47
  • 4
    @Bacher the `+` changes how the `rm -rf` is executed. Without the `+` assuming the find output yields `./foo/node_modules` and `./bar/node_modules` two `rm -rf` commands would get run; one for each path; Including the `+` passes the list of directories to a single `rm -rf` command. In the latter case you would see `rm -rf ./foo/node_modules ./bar/node_modules`. For a more detailed explanation check out the answer here: https://stackoverflow.com/a/6085237 – Frito Jan 31 '20 at 14:59
  • Could add `-type d` – Tyler Christian Jul 02 '20 at 14:36
  • **Mention that this command is to delete `node_modules`, in BOLD LETTERS** – Nitin Kumar May 20 '22 at 07:43