Skip to content

Instantly share code, notes, and snippets.

@jeenuv
Last active April 9, 2018 10:29
Show Gist options
  • Select an option

  • Save jeenuv/c6c09162abe272784491 to your computer and use it in GitHub Desktop.

Select an option

Save jeenuv/c6c09162abe272784491 to your computer and use it in GitHub Desktop.
Cleanup Kindle's orphan SDR directories
#!/bin/bash
# Find in $kindle/document directory, directories without a corresponding .mobi
# or .azw files
set -e
kindle="${kindle:?}"
cd "$kindle/documents"
export force
find -maxdepth 1 -iname '*.sdr' -type d -printf "%f\0" | xargs -0 bash -c \
'for i; do
i="$(echo "$i" | sed "s/.sdr//")"
# Skip my clippings
[ "$i" = "My Clippings" ] && continue
[ -f "$i.azw" ] && continue
[ -f "$i.azw3" ] && continue
[ -f "$i.mobi" ] && continue
if [ "$force" ]; then
rm -rf "$i.sdr";
else
echo "> $i.sdr"
fi
done
' bash
if [ -z "$force" ]; then
echo
echo "Set 'force' to remove the above listed directories"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment