Concatenate PDF files with Ghostscript

I was looking for a way to concatenate PDF (or Postscript) files on Linux today, so that I could easily print some coursebook. Professors have this annoying habit of "conveniently" splitting their books into one PDF for each chapter. Very annoying if you want to print a file double-sided (like the environment-conscious geek you are).

Fortunately, Ghostscript comes to the rescue. Ghostscript comes standard with just about any Linux distribution, and can be installed on all other major operating systems as well.

To concatenate a few PDFs, simply run:

gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-sOutputFile=out.pdf 1.pdf 2.pdf 3.pdf 4.pdf

Replace a4 by letter if you need to print on US Letter pages. It works just as well using Postscript files, of course.