Marcio Cunha

How to merge PDF files on Linux using the terminal

Learn how to quickly and automatically combine multiple PDF documents on Linux using the pdftk command-line utility.

Marcio Cunha•4 min
Also available in:PortuguêsEspañol
Summary
  • The pdftk utility enables manipulating and joining PDF documents directly from the terminal with straightforward commands.
  • Tool installation varies by Linux distribution, utilizing standard package managers like apt or dnf.
  • File merging can be fully automated by combining the command with wildcards to streamline daily workflows.
  • Other day-to-day administrative tasks, such as managing corrupted data, complement system organization just like knowing how to recover deleted files on Linux via terminal .
  • Mastering command-line utilities significantly boosts productivity when handling large volumes of documents.

Why merge PDF files via terminal on Linux?

Handling documents on a daily basis often requires joining multiple reports, invoices, or contracts into a single file. Doing this using graphical interface software can be slow and tedious, especially when dealing with dozens of pages. On Linux, the command line offers much faster and more precise ways to accomplish this task.

Automating repetitive tasks is one of the greatest productivity boosts for open-source system users. When you need to join documents frequently, writing a short script or running a direct command saves precious time. Furthermore, you avoid relying on online tools that require uploading sensitive data to third-party servers, ensuring complete privacy.

To perform this task efficiently, the most recommended tool is pdftk (PDF Toolkit), a Swiss Army knife for manipulating Portable Document Format files. In practice, it allows you to slice, join, tag, and repair files without opening a heavy visual program. Anyone who already manages corrupted files or handles maintenance routines, such as how to recover deleted files on Linux via terminal, will find this tool to be a perfect complement to their workflow.

How to install the pdftk tool on your system

Before you begin joining your documents, you need to ensure the package is installed on your computer. Because the utility is lightweight and widely used, it is present in the official repositories of the vast majority of modern Linux distributions. Installation takes just seconds through the system terminal.

If you use Debian or Ubuntu-based distributions, the process uses the apt package manager. Simply open the command-line window and type the installation instruction with administrator privileges. The system will download the necessary files and configure everything automatically so you can start using it.

sudo apt update && sudo apt install pdftk-java

For users of Red Hat-based distributions, such as Fedora or CentOS, the default manager is dnf. The command follows the same simple package request logic. It is worth noting that modern versions of pdftk often run on top of the Java virtual machine to ensure stability and portability across different operating system versions.

sudo dnf install pdftk

The basic command to join multiple PDF documents

With the tool installed, the merging process is quite intuitive. Imagine you have two files named report1.pdf and report2.pdf in your current folder and want to join them into a single file named final_document.pdf. The command will read the documents in the specified order and concatenate the content sequentially.

In practice, the command structure tells the tool to take the input files, merge them following the stipulated sequence, and save the result to the output file you defined. This approach is excellent for financial reports, academic papers, or scans split into multiple parts.

pdftk report1.pdf report2.pdf cat output final_document.pdf

In this command, the keyword cat comes from the classic Unix command and is used precisely to concatenate the contents of the files listed before the output keyword. If you need to change the order of the documents, simply change the sequence of file names in the command line before running the process.

How to automate merging using wildcards

Typing the name of dozens of files one by one would be tiring and inefficient. Fortunately, the Linux shell allows the use of wildcards, such as the asterisk (*), to select multiple files that share a naming pattern. This turns a time-consuming manual task into a single-command execution.

If your files are named sequentially, such as part1.pdf, part2.pdf, and part3.pdf, or if they start with a common prefix like invoice_2023_*.pdf, you can pass them in batches to the tool. The operating system expands this pattern by sorting the found names alphabetically.

pdftk invoice_*.pdf cat output all_invoices.pdf

This batch processing capability is ideal for anyone dealing with dozens of documents digitized on a scanner. By combining this technique with media organization routines, such as how to convert HEIC to JPG via terminal on Linux, you create a fully automated workspace for managing visual files and text documents. To explore these architectural concepts further in production, see our related technical analysis on How to test SMD crystal oscillator with frequency counter.

Final considerations on document manipulation

Mastering the use of pdftk in the Linux terminal transforms how we handle documents every day. Instead of relying on complex software or paid web tools, the command line offers a fast, secure, and entirely offline solution to merge, separate, and organize PDF files.

Consistent practice of these commands helps solidify knowledge and paves the way for creating Bash scripts that automate even larger tasks. Whether organizing monthly invoices, joining book chapters, or preparing corporate documentation, mastering these tools elevates your level of technical autonomy.