Skip to content

Instantly share code, notes, and snippets.

@mimizone
Last active November 12, 2018 21:43
Show Gist options
  • Save mimizone/dd1dd6565bd3fbff30314ae2a8349c28 to your computer and use it in GitHub Desktop.
Save mimizone/dd1dd6565bd3fbff30314ae2a8349c28 to your computer and use it in GitHub Desktop.
cleanup duplicates in iTunes folder after consolidation crashed in the middle
#!/bin/bash
path=`pwd`
echo "processing $path"
echo "-------------------------------CHECKING FOLDERS-------------------------------"
# list the folders that are most likely duplicates
#remove " 1$", check a folder exists with that name, and delete
folders=`find . | egrep " 1$"`
while read -r f
do
# echo "... $f ..."
d=${f::${#f}-2}
if [ -d "$d" ]; then
echo "delete $d"
rm -r "$d"
fi
done <<< "$folders"
echo "-------------------------------CHECKING FILES-------------------------------"
# list files that are most likely duplicates
# remove " 1\.m..$", check a file exists with that name, and delete
files=`find . | egrep " 1\....$"`
while read -r f
do
# echo "... $f ..."
d=${f::${#f}-6}${f:${#f}-4:${#f}}
if [ -f "$d" ]; then
echo "delete $d"
rm -r "$d"
fi
done <<< "$files"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment