Skip to content

Instantly share code, notes, and snippets.

@pmalek
Created January 20, 2014 15:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pmalek/8521413 to your computer and use it in GitHub Desktop.
Save pmalek/8521413 to your computer and use it in GitHub Desktop.
Bash script to count pages of pdfs in current directory
#!/bin/bash
sum_pages=0
for file in *.pdf ; do
cur_pages=$(pdfinfo $file | awk '/Pages/{print $2}')
echo "pdf: $file has $cur_pages pages."
sum_pages=$(( sum_pages + cur_pages))
done
echo "All pdf files in this directory have $sum_pages pages."
@yolisses
Copy link

thanks!
I suggest using "$file" instead of $file, with irregular files names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment