Last active
April 4, 2017 15:40
-
-
Save danrspencer/1513bd1f1fd0a8bb34a9066618fd68d4 to your computer and use it in GitHub Desktop.
Delete unused files in a static website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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