Skip to content

Instantly share code, notes, and snippets.

@chrismanahan
Created November 4, 2019 02:54
Show Gist options
  • Save chrismanahan/2bc1ab1331c8763303ad95e754061527 to your computer and use it in GitHub Desktop.
Save chrismanahan/2bc1ab1331c8763303ad95e754061527 to your computer and use it in GitHub Desktop.
convert books to mobis
#!/bin/bash
# quick script to convert books to .mobi and put in a designated dir called mobi/
for d in */; do
if [[ $d == "mobis" ]]; then continue; fi
cd "$d"
mobi=$(ls | grep 'mobi$')
epub=$(ls | grep 'epub$')
pdf=$(ls | grep 'pdf$')
if [[ -n $mobi ]]; then
echo "copying mobi"
cp "$mobi" ../mobis/
elif [[ -n $epub ]]; then
echo "convert epub"
name=${epub%.*}.mobi
ebook-convert "$epub" "../mobis/$name"
elif [[ -n $pdf ]]; then
echo "convert pdf"
name=${pdf%.*}.mobi
ebook-convert "$pdf" "../mobis/$name"
fi
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment