Created
June 5, 2015 03:08
-
-
Save jsfaint/fcef6203fe9d6bc54b5a to your computer and use it in GitHub Desktop.
Kindle Utility: Clean orphan sdr folder which books has been removed
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
#!/bin/bash | |
#author: Jia Sui | |
#email: jsfaint@gmail.com | |
#Description: Clean orphan sdr folder which books has been removed. | |
# Check if Kindle was mounted | |
df -h | grep -i kindle > /dev/null | |
if [[ $? -ne 0 ]]; then | |
echo "Kindle was not mounted" | |
exit 1 | |
fi | |
#Search for Kindle mount point | |
mpoint=`df -h | grep -i kindle | awk '{print $NF}'` | |
KINDLE_DOC="$mpoint/documents" | |
FOLDER_LIST=" | |
$KINDLE_DOC/* | |
$KINDLE_DOC/dictionaries/* | |
" | |
for i in $FOLDER_LIST | |
do | |
for TEST in $i | |
do | |
#Check if it is folder | |
[ ! -d $TEST ] && continue | |
#Check if the name end with sdr | |
echo $TEST | grep "[.]sdr\$" > /dev/null | |
[[ $? -ne 0 ]] && continue | |
TEST2=$(ls -Al "`dirname \"$TEST\"`""/""`echo "$TEST"| sed 's|.*\/\([^\.]*\)\(\..*\)$|\1|g'`".*"" | grep -v 'sdr' | grep "`dirname \"$TEST\"`" ) | |
if [ -z "$TEST2" ]; then | |
echo "Remove $TEST" | |
rm -rf "$TEST" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment