How to Merge PDF Files on Linux: Command Line and Online Methods
Linux users have a rich ecosystem of PDF tools available at the command line, making it one of the best platforms for PDF manipulation — especially for batch processing and automation. But knowing which tools to use, what commands to run, and when to use a simpler online alternative takes some practical knowledge. This guide covers the most useful command-line methods for merging PDFs on Linux, including pdftk, ghostscript (gs), and pdfunite. It also explains when using an online browser-based tool like LazyPDF makes more sense — particularly for quick, one-off merges where firing up a terminal isn't necessary. Whether you're running Ubuntu, Debian, Fedora, Arch, or any other Linux distribution, the tools and techniques in this guide will work. Most are available in standard package repositories and install with a single command. Merging PDFs is one of the most common document operations on Linux — it comes up in scripts that compile monthly reports, combine chapter files into complete books, merge scanned pages into single documents, and countless other workflows. Understanding multiple approaches lets you choose the right tool for each situation.
Merge PDFs on Linux Using pdftk
pdftk (PDF Toolkit) is the most popular and versatile command-line PDF tool on Linux. It handles merging, splitting, rotating, watermarking, and much more with a clean, readable syntax. If you're doing serious PDF work on Linux, pdftk should be your first install.
- 1Install pdftk: on Ubuntu/Debian run `sudo apt install pdftk`, on Fedora run `sudo dnf install pdftk`, on Arch use `yay -S pdftk`.
- 2Navigate to the directory containing your PDFs: `cd /path/to/your/pdfs`
- 3Merge two PDFs with: `pdftk file1.pdf file2.pdf cat output merged.pdf`
- 4Merge multiple PDFs in order: `pdftk doc1.pdf doc2.pdf doc3.pdf cat output combined.pdf`
- 5Merge all PDFs in a directory: `pdftk *.pdf cat output all_merged.pdf`
Merge PDFs on Linux Using Ghostscript
Ghostscript (gs) is a powerful PostScript and PDF interpreter available on virtually every Linux system. It's often already installed since many applications depend on it. The merge command is slightly more verbose than pdftk, but Ghostscript gives you more control over output quality and compression settings. The basic ghostscript merge command is: ``` gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged.pdf file1.pdf file2.pdf file3.pdf ``` This command processes the input files in order and writes the merged PDF to `merged.pdf`. The flags mean: `-dBATCH` exits after processing, `-dNOPAUSE` doesn't pause between files, `-q` runs in quiet mode (minimal output), and `-sDEVICE=pdfwrite` specifies PDF output. Ghostscript also lets you control output quality with the `-dPDFSETTINGS` flag. Use `/screen` for smallest files, `/ebook` for balanced quality, `/prepress` for highest quality suitable for printing. For merging without recompression, ghostscript can be less ideal than pdftk since it may re-encode PDF content.
Merge PDFs on Linux Using pdfunite
pdfunite is a simpler, faster alternative that's part of the poppler-utils package. It's ideal when you want a quick merge without the full pdftk installation. The syntax is extremely simple: `pdfunite file1.pdf file2.pdf output.pdf`. Install poppler-utils on Ubuntu/Debian with `sudo apt install poppler-utils`. On Fedora, it's `sudo dnf install poppler-utils`. On Arch, install `poppler`. The pdfunite command doesn't re-encode PDF content, making it very fast and preserving the original quality of each input file exactly. For simple merges where speed matters and you don't need fancy features, pdfunite is the cleanest solution. One limitation: pdfunite doesn't support all PDF features like interactive forms and some encryption. For documents with those features, use pdftk instead.
When to Use an Online Tool Instead of the Command Line
Command-line tools are powerful, but they're not always the right choice. For quick, one-off merges — especially on a system where you haven't configured your PDF tools yet — a browser-based tool like LazyPDF is often faster. LazyPDF processes merges locally in your browser using the same underlying technology as pdf-lib. On Linux, just open Firefox or Chromium, go to lazy-pdf.com/en/merge, and drag your files in. The merge happens in your browser without installing anything. This approach is particularly useful on freshly installed Linux systems, on systems where you don't have sudo access to install packages, or when you're helping a Linux-using colleague who isn't comfortable with the terminal. The online tool handles file ordering with drag-and-drop, making it more intuitive for occasional use. For automated, scripted, or batch operations where you're processing dozens or hundreds of files, the command-line tools remain superior. For occasional manual merges, the online tool is often more convenient.
Frequently Asked Questions
Which is better for merging PDFs on Linux: pdftk, ghostscript, or pdfunite?
For most users, pdftk offers the best balance of power and usability. pdfunite is faster and simpler for basic merges. Ghostscript is best when you also need to control compression or output quality during the merge. All three are free and excellent — install pdftk first and add others as needed.
Can I merge PDFs on Linux without installing any software?
Yes. Use a browser-based tool like LazyPDF in Firefox or Chromium. The merge runs locally in your browser without any installation. This is also useful on systems where you don't have sudo/root access to install packages.
How do I merge all PDFs in a directory on Linux in alphabetical order?
Use pdftk with a wildcard: `pdftk *.pdf cat output merged.pdf`. The shell expands `*.pdf` in alphabetical order, so files merge in filename order. If you need a specific order, rename files with numeric prefixes (01_chapter.pdf, 02_chapter.pdf) before merging.
Will merging PDFs on Linux change the file quality?
pdftk and pdfunite merge PDFs without re-encoding content, preserving original quality. Ghostscript may re-encode content depending on settings, which can affect quality. For quality-preserving merges, use pdftk or pdfunite. For merges that also apply compression, use ghostscript with appropriate settings.