Skip to content

Instantly share code, notes, and snippets.

@sukima
Created May 5, 2020 19:16
Show Gist options
  • Save sukima/c7d56a6e42f3b78ca8957bc31ae02100 to your computer and use it in GitHub Desktop.
Save sukima/c7d56a6e42f3b78ca8957bc31ae02100 to your computer and use it in GitHub Desktop.
Forcfully remove old node_modules recursivly
#!/bin/bash
DIR="${1##/}"
DIR="${DIR-:.}"
entries=$(mktemp)
trap 'rm -f "$entries"' EXIT
find "${DIR}" -name node_modules -prune -atime +30d > "$entries"
if [[ ! -s "$entries" ]]; then
exit 0
fi
echo "About to DESTROY the following directories:"
cat "$entries"
echo
read -n 1 -p "Are you sure? [y/N]" confirmation
if [[ $confirmation != "y" && $confirmation != "Y" ]]; then
exit 0
fi
while read entry; do
nice rm -rf "$entry" &
done < "$entries"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment