Skip to content

Instantly share code, notes, and snippets.

@esaborit4code
Last active January 9, 2017 11:25
Show Gist options
  • Save esaborit4code/5868140 to your computer and use it in GitHub Desktop.
Save esaborit4code/5868140 to your computer and use it in GitHub Desktop.
Bash script to find unused images within a project's folder. Based on Volomike's script at http://stackoverflow.com/a/8174681
#!/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!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment