---
title: "How to Merge PDF Files in the Linux Terminal"
description: "Working with contracts and other legal documents gets easier once you know how to digitally sign and edit PDFs. It can simply become a minor inconvenience once you know how to merge PDF files in the..."
url: https://www.inmotionhosting.com/support/server/linux/how-to-merge-pdf-files-linux/
date: 2021-04-14
modified: 2024-10-09
author: "InMotion Hosting Contributor"
categories: ["Linux"]
type: post
lang: en
---

# How to Merge PDF Files in the Linux Terminal

![How to Merge PDF Files in the Linux Terminal - 4 Options](https://www.inmotionhosting.com/support/wp-content/uploads/2021/04/canva-how-to-merge-pdf-files-in-linux-1024x538.jpg)

Working with contracts and other legal documents gets easier once you know how to digitally sign and edit PDFs. It can simply become a minor inconvenience once you know how to merge PDF files in the Linux terminal or any free graphical application. Then, you’re not stuck [adding multiple PDFs to your website](https://www.inmotionhosting.com/support/website/how-to-add-a-pdf-file-to-your-website/), annoying your readers and business partners as a result.

[![How to merge PDF files in Libre Office Draw](https://www.inmotionhosting.com/support/wp-content/uploads/2021/04/libreoffice-draw-pdf-export.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2021/04/libreoffice-draw-pdf-export.png)

A lot of desktop and online options show in search engine results for “how to merge two PDF files.” Some of the most popular, reputable applications:

- [Adobe Acrobat Reader](https://acrobat.adobe.com/us/en/acrobat/pdf-reader.html#tt)
- [Foxit Merge PDF](https://www.foxit.com/merge-pdf/)
- [LibreOffice Draw](https://www.libreoffice.org/discover/draw/)
- [Master PDF Editor](https://code-industry.net/masterpdfeditor/)
- [PDFZorro](https://www.pdfzorro.com/)

Problem is that none of those above are free, light-weight, private, *and* fitting answers for how to merge PDF files in the Linux server command line interface (CLI). Below we’ll cover:

- [How to Merge PDF Files in the Linux Terminal](#how)
  - [Convert ImageMagick Tool](#convert)
  - [Ghostscript](#ghostscript)
  - [PDFunite](#pdfunite)
  - [PDFtk (PDF Toolkit)](#pdftk)

If you don’t need cPanel, don’t pay for it. Only pay for what you need with our scalable [Cloud VPS Hosting](https://www.inmotionhosting.com/cloud-vps).

![check mark](https://design.inmotionhosting.com/assets/icons/standard/check-blue.svg)CentOS, Debian, or Ubuntu ![check mark](https://design.inmotionhosting.com/assets/icons/standard/check-blue.svg)No Bloatware ![check mark](https://design.inmotionhosting.com/assets/icons/standard/check-blue.svg)SSH and Root Access

## How to Merge PDF Files in the Linux Terminal

1. First, open a Linux terminal. If working on a Linux server, [log into SSH](https://www.inmotionhosting.com/support/server/ssh/how-to-login-ssh/). cPanel server administrators can use [cPanel Terminal](https://www.inmotionhosting.com/support/edu/cpanel/how-to-launch-the-cpanel-terminal/) or [WebHost Manager (WHM) Terminal](https://www.inmotionhosting.com/support/edu/whm/how-to-open-a-terminal-connection-in-whm/). [Root access](https://www.inmotionhosting.com/support/amp/obtain-root-access/) won’t matter in most cases.
2. These commands are easier when you don’t have to repeatedly type full file paths from your home directory. If all or most PDF files are in the same directory, navigate to that directory with the [`cd` command](https://www.inmotionhosting.com/support/server/linux/using-the-linux-cd-command/). 
3. Before installing a PDF merger below, check if you already have a PDF editor installed. Type `pdf` and press Tab twice to see what programs are listed. If anything shows up, check the manual to learn what it does: man pdfapplication

### Convert ImageMagick Tool

[**ImageMagick**](https://www.inmotionhosting.com/support/website/is-imagemagick-installed-on-the-servers/) is installed on all InMotion cPanel servers. Primarily for image optimization, ImageMagick includes a conversion tool that can merge PDFs: `convert`. Type the program command, original PDFs in the order to be merged, then the filename for the final, merged PDF file.

convert file1.pdf file2.pdf mergedfile.pdf

You may receive the following error on a cPanel server- `convert: unable to access configure file `delegates.xml' @ warning/configure.c/GetConfigureOptions/677.` If so, run `convert` by itself. If that returns info about using the tool, your cPanel server administrator may have set your user to a [jailed shell](https://www.inmotionhosting.com/support/edu/cpanel/managing-shell-access/) for better security, removing your access to the ImageMagick delegates.xml file. We recommend trying GhostScript (below) before asking for normal shell access.

To merge specific pages from PDFs, specify the pages starting from 0. For example, to merge pages 1-2 of a PDF with a second file:

convert file1.pdf[0-1] file2.pdf mergedfile.pdf

Install ImageMagick on CentOS:

sudo yum install ImageMagick

Install ImageMagick on Debian / Ubuntu:

sudo apt install imagemagick

Learn more about how to convert and resize files with [ImageMagick](https://www.inmotionhosting.com/support/edu/software/using-imagemagick/).

### Ghostscript

[**Ghostscript**](https://www.ghostscript.com/) is installed on InMotion cPanel servers, CentOS cloud servers, and many desktop Linux distros. It is a versatile CLI app for manipulating PDF, XPS, and PostScript files. We’ll use `-dNOPAUSE` to disable continuation prompts at the end of each page. The `-sDEVICE` attribute designates the output device or function. You can see the full list with `gs -h` command.

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=mergedfile.pdf -dBATCH file1.pdf file2.pdf

Install Ghostscript on CentOS:

sudo yum install ghostscript

Install Ghostscript on Debian / Ubuntu:

sudo apt-get install ghostscript

### PDFunite

`pdfunite`, by [Poppler](https://poppler.freedesktop.org/), is natively installed on Ubuntu-based Mint Cinnamon and Arch-based Manjaro. The command format is the same as the convert tool.

pdfunite file1.pdf file2.pdf mergedfile.pdf

Install PDFunite on CentOS:

sudo dnf install poppler-utils

Install PDF on Debian / Ubuntu:

sudo apt install poppler-utils

### PDFtk (PDF Toolkit)

[**The PDF Toolkit**](https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/) has graphical and paid options. The format is a little different for PDFtk. You must add “cat output” between the original PDFs and the new PDF file.

pdftk file1.pdf file2.pdf cat output mergedfile.pdf

See official documentation to [install PDFtk on CentOS 6](https://www.pdflabs.com/docs/install-pdftk-on-redhat-or-centos/).

To install PDFtk on CentOS 7, read more about libgcj dependency issues and possible solutions from a [docsplit GitHub thread](https://github.com/documentcloud/docsplit/issues/123).

Install PDFtk on [Debian](https://packages.debian.org/buster/pdftk-java) / Ubuntu:

sudo apt install pdftk-java

Learn more from our [Cloud Server Hosting Product Guide](https://www.inmotionhosting.com/support/product-guides/cloud-server/).
