Lego2012
9/26/2016 - 11:49 PM

Terminal - Find Orphans

Terminal - Find Orphans

#!/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!!"