Lego2012
1/9/2017 - 11:25 AM

find unused images within a project's folder

find unused images within a project's folder

#!/bin/bash

# Based on Volomike's script at http://stackoverflow.com/a/8174681

MYPATH=$1
ALL_IMAGES=$MYPATH/all_images
UNUSED_IMAGES=$MYPATH/unused_images

echo "" > $ALL_IMAGES
for format in jpg jpeg png gif; do
  echo "Search for $format images started"
  find "$MYPATH" -name *.$format -exec basename {} \; >> $ALL_IMAGES;
  echo "Search for $format images finished"
done

echo "" > $UNUSED_IMAGES
for image in $(cat $ALL_IMAGES); do
  echo "Search for usages of $image started"
  grep -R $image "$MYPATH" > /dev/null || echo $image >> $UNUSED_IMAGES
  echo "Search for usages of $image finished"
done
echo "All finished!!"