Skip to content

Instantly share code, notes, and snippets.

@arnaudlimbourg
Created April 16, 2021 15:36
Show Gist options
  • Save arnaudlimbourg/acc8cdae56a00d0f52557739420af96b to your computer and use it in GitHub Desktop.
Save arnaudlimbourg/acc8cdae56a00d0f52557739420af96b to your computer and use it in GitHub Desktop.
Delete images files which names cannot be found in the code base
IMAGES_LOCATION="./"
FILES=`find $IMAGES_LOCATION -not -name '*.scss'`
# loop through the file list, exclude the extension to be very safe
# and remove the files that have no match. This approach is conservative
# since we might keep files that are no used due to a different extension
# but it should not happen a lot
for FILE in $FILES; do
FULLNAME=$(basename "$FILE")
BASE="${FULLNAME%%.*}"
# git grep $BASE > /dev/null || echo "Would remove $BASE ($FILE)"
git grep $BASE > /dev/null || git rm $FILE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment