Last active
June 19, 2018 13:39
-
-
Save jag1989/b17752899de3bbb91ac227eb962e36d5 to your computer and use it in GitHub Desktop.
Extract asset paths and delete unused
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd ~/www/mduk/htdocs && find assets -type f > ./asset-paths-source-test.txt | |
count=$(wc -l < ~/www/mduk/htdocs/asset-paths-source-test.txt) | |
echo "Created ~/www/mduk/htdocs/asset-paths-source-test.txt" | |
echo "Total Asset Paths: $count" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grep "\/assets\/[0-9]{4}\/[0-9]{4}\/(.*?)(\.(doc|pdf|jpg|jpeg|png|gif|mp3|mov|wmv|rtf|mp4|com|swf)|\'|\"|\s|\<\/)" -E -i -o ~/Downloads/wp-content/mysql.sql | perl -ne '$H{$_}++ or print' > asset-paths-uniq.txt | |
sed -i.bak -e 's/^\///' -e 's/\\\"$//' asset-paths-uniq.txt | |
grep -v -f asset-paths-uniq.txt ~/www/mduk/htdocs/asset-paths-source.txt > assets-unused.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while read file; do | |
path="/Users/jonathangarrett/www/mduk/htdocs/" | |
rm $path$file | |
done < assets-unused.txt | |
cd ~/www/mduk/htdocs/assets && find . -empty -type d -delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
countassetfolders=$(cd ~/www/mduk/htdocs/assets && ls -lR | grep "^d" | wc -l) | |
fullassetlist=$(wc -l < ~/www/mduk/htdocs/asset-paths-source-test.txt) | |
uniqueassets=$(wc -l < asset-paths-uniq.txt) | |
toberemoved=$(wc -l < assets-unused.txt) | |
echo "Source Total Asset Paths: $fullassetlist" | |
echo "Source Total Asset Folders $countassetfolders" | |
echo "Unique Asset Paths in SQL: $uniqueassets" | |
echo "Count to be removed: $toberemoved" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment