#!/bin/sh for FILE in $(git ls-files ./img); do # echo files that should be removed # git grep $(basename "$FILE") > /dev/null || echo "would remove $FILE" # remove files that should be removed git grep $(basename "$FILE") > /dev/null || git rm "$FILE" done # credit: https://tanzu.vmware.com/content/blog/a-simple-way-to-detect-unused-files-in-a-project-using-git # Do not forget to add execution rights to the file: > chmod +x remove-images.sh # Run the script with: > ./remove-images.sh