Skip to content

Instantly share code, notes, and snippets.

@forabi
Created August 1, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save forabi/b48a66af41f439df27e9 to your computer and use it in GitHub Desktop.
Save forabi/b48a66af41f439df27e9 to your computer and use it in GitHub Desktop.
Get total page count for all PDF files in the current working directory. Requires pdfinfo
#!/bin/bash
num_pages=0;
for file in *.pdf; do
f_pages=$(pdfinfo "$file" 2>/dev/null | grep Pages | cut -d ":" -f 2 | sed -e 's/^[ \t]*//')
if [[ -z $f_pages ]]; then
echo "Error in $file" && exit 1;
fi
num_pages=$(( num_pages + $f_pages ))
done
echo $num_pages;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment