Last active
April 9, 2018 10:29
-
-
Save jeenuv/c6c09162abe272784491 to your computer and use it in GitHub Desktop.
Cleanup Kindle's orphan SDR directories
This file contains hidden or 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 | |
| # 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