How to Merge PDF Files in the Linux Terminal

Working with multiple PDF files is common when managing reports, invoices, manuals, or project documents. Instead of handling several individual files, you can combine them into a single PDF for easier sharing and organization. Linux offers several command-line tools that allow you to merge PDF files quickly without installing a desktop PDF editor.

This guide explains different methods to merge PDF files in the Linux terminal using PDFunite, Ghostscript, PDFtk, and ImageMagick.

Prerequisites

  • Linux system with terminal access.
  • Two or more PDF files.
  • Sudo or root privileges to install utilities.
Method 1: Merge PDF Files Using PDFunite

Install:
sudo apt install poppler-utils

Merge:
pdfunite file1.pdf file2.pdf merged.pdf

PDFunite is lightweight, preserves formatting, and is ideal for everyday PDF merging tasks.

Method 2: Merge PDF Files Using Ghostscript

Install:
sudo apt install ghostscript

Merge:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf file1.pdf file2.pdf

Ghostscript is useful for advanced PDF processing and produces reliable output.

Method 3: Merge PDF Files Using PDFtk

Install:
sudo apt install pdftk

Merge:
pdftk file1.pdf file2.pdf cat output merged.pdf

PDFtk offers additional PDF management features such as splitting and encryption.

Method 4: Merge PDF Files Using ImageMagick

Install:
sudo apt install imagemagick

Merge:
convert file1.pdf file2.pdf merged.pdf

Note: Some Linux distributions restrict PDF processing in ImageMagick for security reasons.

Verify the Merged PDF

Open the merged file and verify that all pages appear correctly, formatting is preserved, and the document opens without errors.

Best Practices

  • Keep backups of original PDFs.
  • Use meaningful filenames.
  • Store files in one directory.
  • Verify the merged output before sharing.

Linux provides several reliable command-line utilities for merging PDF files efficiently. Whether you choose PDFunite, Ghostscript, PDFtk, or ImageMagick, each tool offers a practical way to combine documents while maintaining quality. Select the method that best suits your workflow and verify the final document before sharing or archiving.

Explore our Knowledge Base guide: How to Insert a PDF in WordPress Without Using a Plugin

Share:

Popular Posts You May Read

Explore more hosting insights, tips and industry updates.

How to Clear DNS Server Cache on Windows

How To Clear The Local DNS Cache In Windows is the subject of this article.…

How can I upload files on an add-on domain?

You must download the files for add-on domain to it’s webroot directory. When producing a…

PHP Script to Test MySQL Database Connectivity

A test for MySQL database connectivity is done using the PHP script mentioned below. It…