Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kindle Utility: Clean orphan sdr folder which books has been removed
#!/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
You can’t perform that action at this time.