Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bulletinmybeard/4925339cd89fabc4ce436e2e8515bba7 to your computer and use it in GitHub Desktop.
Save bulletinmybeard/4925339cd89fabc4ce436e2e8515bba7 to your computer and use it in GitHub Desktop.
Delete all `node_modules` folders recursively (Linux / macOS / Windows)

macOS

# Search in the Spotlight index
# https://developer.apple.com/library/archive/documentation/Carbon/Conceptual/SpotlightQuery/Concepts/Introduction.html
mdfind "kMDItemFSName=node_modules && kMDItemContentType=public.folder" | xargs rm -rf

# Simple, fast and user-friendly alternative to find (brew install fd)
# https://github.com/sharkdp/fd
fd -t d -H -E node_modules | xargs rm -rf

Linux

# Search in Unix-like systems (works on macOS also!)
# https://man7.org/linux/man-pages/man1/find.1.html
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
or
find . -type d -name "node_modules" -delete

Windows

for /d /r . %d in (node_modules) do @if exist "%d" rd /s /q "%d"
@BANG88
Copy link

BANG88 commented Jul 8, 2024

fd -t d -H -E node_modules | xargs rm -rf

Please don't run this on your computer.....
WTF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment