Skip to content

Instantly share code, notes, and snippets.

@jico
Last active January 4, 2016 20:39
Show Gist options
  • Save jico/8675139 to your computer and use it in GitHub Desktop.
Save jico/8675139 to your computer and use it in GitHub Desktop.
Finds and removes possible unused assets in your Rails app.
#!/bin/bash
#
# Delete probably unused assets (images) under app/assets
for DIRECTORY in $(find app/assets -type d)
do
echo -e "Searching files in $DIRECTORY..."
for FILEPATH in $(find $DIRECTORY -type f -name '*.jpg' -o -name '*.jpeg' -o -name '*.gif' -o -name '*.png')
do
FILENAME=$(basename $FILEPATH)
if [[ -n $(grep -R $FILENAME app/) ]]; then
echo "$FILENAME"
else
rm -f $FILEPATH
red='\x1B[0;31m'
NC='\x1B[0m'
echo -e "${red}$FILEPATH deleted${NC}"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment