For printing (e.g. a thesis), it might be cheaper to print some pages in black and white instead of colour. Printers’ web sites often ask you to put in the number of colour pages. To avoid counting by hand you can use ghostscript, which should be installed on all normal desktop Linux systems.
gs -q -o - -sDEVICE=inkcov YOURPDF.pdf
will output four numbers for every page: percentage of cyan, magenta,
yellow, and black on the page. The
-q argument suppresses some
additional output (including the page numbers), so leave it out if you
-o - simply tells ghostscript to output the information to
the screen. Replace the second dash by a filename if you want the
output to be written to a file. The
inkcov device calculates the
colour percentages and writes the output, see the ghostscript
for more details.
You can now count pages without colour using
gs -q -o - -sDEVICE=inkcov YOURPDF.pdf \ | grep '^ 0.00000 0.00000 0.00000' \ | wc -l
In order to count the colour pages, use
gs -q -o - -sDEVICE=inkcov YOURPDF.pdf \ | grep -v '^ 0.00000 0.00000 0.00000' \ | wc -l
I found this trick on tex.stackexchange.com and wrote it down here for easy reference.