Skip to content

Instantly share code, notes, and snippets.

@jsfaint
Created June 5, 2015 03:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsfaint/fcef6203fe9d6bc54b5a to your computer and use it in GitHub Desktop.
Save jsfaint/fcef6203fe9d6bc54b5a to your computer and use it in GitHub Desktop.
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