Skip to content

Instantly share code, notes, and snippets.

@danrspencer
Last active April 4, 2017 15:40
Show Gist options
  • Save danrspencer/1513bd1f1fd0a8bb34a9066618fd68d4 to your computer and use it in GitHub Desktop.
Save danrspencer/1513bd1f1fd0a8bb34a9066618fd68d4 to your computer and use it in GitHub Desktop.
Delete unused files in a static website
#!/usr/bin/env bash
TEMP="./tmp"
REGEX="img\/[^>]+?(\"|\)|'| )"
ROOTPATH="./public"
PATH_TO_CLEAN="./public/img"
egrep -iowhr "$REGEX" * | rev | cut -c 2-1000 | rev | xargs -I {} sh -c "mkdir -p $TEMP/{} && rm -r $TEMP/{} && cp $ROOTPATH/{} $TEMP/{}"
rm $TEMP/{}
find $TEMP -type d -empty -delete
rm -rf $PATH_TO_CLEAN
mkdir $PATH_TO_CLEAN
cp -R $TEMP/ $ROOTPATH
rm -rf $TEMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment