Skip to content

Instantly share code, notes, and snippets.

@varunkumar
Created October 25, 2018 05:14
Show Gist options
  • Save varunkumar/e8ad001a50cd8680a2cb4521bf01650c to your computer and use it in GitHub Desktop.
Save varunkumar/e8ad001a50cd8680a2cb4521bf01650c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script for cleaning up node_modules and other tmp files (like core)
# Usage: ./cleanup-space.sh -m +15
# This will cleanup node modules not accessed in the last 15 days
VERSION=0.1.0
# Defaults
CLEANUP_TIME=+15
VERBOSE=TRUE
INTERACTIVE_FLAG=
# Parse arguments
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-m|--mtime)
CLEANUP_TIME="$2"
shift
;;
-h|--help)
echo "cleanup-space.sh [-m|--mtime] [+15] [-h|--help] [--version] [-v|--verbose] [-i|--interactive]"
exit
;;
--version)
echo $VERSION
;;
-v|--verbose)
VERBOSE=true
;;
-i|--interactive)
INTERACTIVE_FLAG=-I
;;
*)
;;
esac
shift # past argument or value
done
# logger util
function log () {
if [ ! -z $VERBOSE ]
then
echo "$@"
fi
}
if [ ! -z $VERBOSE ]
then
PRINT_FLAG=-print
fi
log "Cleaning up node_modules with mtime $CLEANUP_TIME"
find . -name "node_modules" -prune -mtime $CLEANUP_TIME $PRINT_FLAG -exec rm -rf $INTERACTIVE_FLAG '{}' \;
log "Cleaning up core files"
find . -name "core" -type f $PRINT_FLAG -exec rm -rf $INTERACTIVE_FLAG '{}' +
log "Done cleaning up space"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment