Skip to content

Instantly share code, notes, and snippets.

@kisom
Created December 4, 2011 15:23
Show Gist options
  • Save kisom/1430446 to your computer and use it in GitHub Desktop.
Save kisom/1430446 to your computer and use it in GitHub Desktop.
quickly sort my oreilly downloads
#!/bin/sh
# 2011-12-04 kyle isom <[email protected]>
# designed to quickly move all mah oreilly downloads to a folder where i
# can sort them
# assumptions:
# the only epubs are from o'reilly
# i download several formats for each book (pdf, epub, mobi)
# my main ebook library is organised by topic/.../title/title.*
# after i run this, i open the target directory and filter the files into
# the main library from there.
targetdir="$1"
if [ ! -d $targetdir ]; then
if [ -e $targetdir ]; then
echo "[!] please pass in either the directory to create or a directory"
exit 1
fi
mkdir $targetdir
fi
for book in $(ls *.epub)
do
if [ -z "$book" ]; then
continue
fi
title="$(echo ${book##/*} | sed -e 's/\(..*\)\..*/\1/')"
echo "[+] processing $title"
mkdir $title
printf "\t"
mv -v ${title}.* ${title}/
mv $title/ $targetdir/
done
echo
echo "[+] finished!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment