Combine multiple PDFs into one file in Linux

One thing which I find myself doing on a regular basis is combining multiple PDFs into a single file – e.g. scanned receipts with a digital expenses form. This is a fairly simple task in Linux, and can be achieved with a single command line invocation.


On most Linux systems the only package you should need to install is Ghostscript. This can be achieved by running the relevant command as root (or via sudo).

  • Ubuntu: apt-get install ghostscript
  • Fedora: yum install ghostscript
  • Gentoo: emerge ghostscript-gpl

Other distributions will likely have Ghostscript available as a package, as it is a popular piece of free software.

Combining files

To combine two or more files into a single PDF, run the following command:

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combined.pdf -dBATCH one.pdf two.pdf

Here is what each command line parameter does (see man gs for full details).

  • -dNOPAUSE: Disables the prompt and pause at the end of each page.
  • -sDEVICE: Selects an output device, in this case pdfwrite.
  • -sOUTPUTFILE: Selects an output file.
  • -dBATCH: List of files to be combined, separated by spaces. The order the files appear on the command line is the order they will appear in the combined PDF.


  1. Dan Poltawski

    I’ve used pdftk for this in the past – I think its a little simpler 😉

  2. Paul

    I’ll have to have a look at pdftk – I’ve used it for finding the names of form fields so they can be auto-populated using a script (which I should blog about at some point), but not much else.

    I think I’ve stuck with Ghostscript so far because it’s what I know, and therefore I’ve never had any reason to change. 🙂

Leave a Reply to Dan Poltawski Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.