Skip to content

Instantly share code, notes, and snippets.

@t27
Created December 14, 2016 13:35
Show Gist options
  • Save t27/bf68fdcea3bb4213cdbcb3397b9a886c to your computer and use it in GitHub Desktop.
Save t27/bf68fdcea3bb4213cdbcb3397b9a886c to your computer and use it in GitHub Desktop.
Bash script to find all pdf files in a folder and subfolders, use the unix 'file' command to check its actual type and rename to .epub or .html accordingly (used for renaming glitchy google play books takeout files)
EPUBSTR="EPUB document"
HTMLSTR="XML document text"
for f in */*.pdf
do
VAR1=$(file -b "$f")
# echo $VAR1
if [[ "$VAR1" == "$EPUBSTR" ]];
then
fnew=${f/%.pdf/.epub}
mv "$f" "$fnew"
elif [[ "$VAR1" == "$HTMLSTR" ]];
then
fnew2=${f/%.pdf/.html}
mv "$f" "$fnew2"
else
echo "Not an epub"
fi
# do something on $f
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment