Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

gatesphere commented Nov 20, 2012

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

@Paretzky

This comment has been minimized.

Copy link
Owner Author

Paretzky commented Nov 21, 2012

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

This comment has been minimized.

Copy link
Owner Author

Paretzky commented Nov 21, 2012

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

This comment has been minimized.

Copy link
Owner Author

Paretzky commented Nov 21, 2012

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
You can’t perform that action at this time.