Skip to content

Instantly share code, notes, and snippets.

@Paretzky
Created November 18, 2012 12:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Paretzky/4105017 to your computer and use it in GitHub Desktop.
Save Paretzky/4105017 to your computer and use it in GitHub Desktop.
Total the Number of Pages in All Pdf's in the Current Directory Recursively
find . -type f -iname "*pdf" | xargs -0 -d "\n" -n 1 pdfinfo 2> /dev/null | grep Pages | grep -Eo "[[:digit:]]+" | tr "\n" "+" | grep -Eo "[[:digit:]]+(\+[[:digit:]]+)+" | bc
@gatesphere
Copy link

... while this is awesome, it's also one of those "why would you ever need this" moments.

@Paretzky
Copy link
Author

I was printing off a bunch of papers to read on a trip. Before just sending all of them off as one big print job I wanted to see how many pages of my quota that would actually take.

@Paretzky
Copy link
Author

Oh yeah, pdfinfo sometimes spits out extra stuff when it has issues parsing a pdf completely. The answer, in my minimal works for me style testing, will always be the last line outputed.

@Paretzky
Copy link
Author

4983541063155bb5583946cdc5863c5830f9da6a add case insensitive matching *pdf files, and removes pdfinfo's stderr complaints.

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