Skip to content

Instantly share code, notes, and snippets.

@morido
Created March 30, 2014 18:23
Show Gist options
  • Save morido/9877322 to your computer and use it in GitHub Desktop.
Save morido/9877322 to your computer and use it in GitHub Desktop.
Sum up number of PDF pages in a directory
#!/bin/bash
# This sums up the number of pages of all pdfs in a given directory
counter=0
hash pdfinfo 2>/dev/null || { echo >&2 "pdfinfo is required, but not installed. Aborting."; exit 1; }
if [ -n "$1" ]; then dir=$1; else dir="."; fi
for file in $dir/*.pdf; do
currentcount=$(pdfinfo "$file" | sed -n 's/^Pages:\s*\([0-9]\+\)/\1/p')
counter=$((counter+currentcount))
done
echo $counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment