`rm` and `mv` touch the index, not the data — why `node_modules` takes forever

Today I Learned · August 8, 2026

rm and mv touch the index, not the data — why node_modules takes forever

rm does not erase your file from disk. Neither does mv “move” your file. Both work on the filesystem’s index — the metadata that says “this name points at this data” — which is why deleting a folder with hundreds of thousands of files is slow while these commands feel instant for a single file.

What rm really does

A file name is a directory entry pointing to an inode: the record holding the file’s metadata and the pointers to its data blocks. rm doesn’t touch that data. It calls the unlink() syscall, which:

  1. removes the directory entry, and
  2. decrements the inode’s link count; when it hits zero, the blocks are marked free.

The bytes stay physically on disk. A forensic lab with the right equipment can recover the file if nothing has overwritten those blocks since — this is exactly how deleted files get recovered.

What mv really does

The node_modules problem

rm -rf node_modules isn’t slow because of the data size — it’s slow because the kernel must walk the tree and issue one unlink() syscall per file (plus rmdir() per directory). node_modules routinely has 100k+ individual entries, so “one command” is secretly hundreds of thousands of metadata operations.

The same applies to mv node_modules across disks: every one of those files gets copied and then unlinked one by one.

Gotchas