Skip to content

Instantly share code, notes, and snippets.

@johnghill
Last active July 6, 2023 19:13
Show Gist options
  • Save johnghill/5e6b228191fb152663e58d760d499dc9 to your computer and use it in GitHub Desktop.
Save johnghill/5e6b228191fb152663e58d760d499dc9 to your computer and use it in GitHub Desktop.
[bash] Count pages in all PDFs in current folder and its sub folders
#!/bin/bash
# Based on https://gist.github.com/pmalek/8521413
sum_pages=0
while IFS= read -r file; do
cur_pages=$(pdfinfo "$file" | awk '/Pages/{print $2}')
echo "pdf: $file has $cur_pages pages."
sum_pages=$(( sum_pages + cur_pages))
done < <(find . -name "*.pdf" -type f)
echo "All pdf files in this directory and its subdirectories have $sum_pages pages."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment