I have 86 PDFs that I don't want to share on the internet and merge with online tools. I am using the PopOS Linux distro and I would like to merge it using the terminal.

PDF names are like 1.SubjectA, 2. SubjectB (start with Number. , so they are well ordered) Here is what I found but none of them are merging in order:

qpdf --empty --pages *.pdf -- out.pdf

Example file names:

1. Why to learn System and Network.pdf
2. Network, Hardwares, LAN-WAN.pdf
3. Protocols-Ports, OSI-TCP IP.pdf

Pattern is Number + .(dot) + space + name

  • Create a bash script with this content (and give execution perms): qpdf --empty --pages "$@" -- out.pdf and in your terninal type: printf -- "%s\0" ./*.pdf | sort -zV | xargs -0 ./script Commented Dec 14, 2022 at 8:48

2 Answers 2


With all the files in the one directory one can get rid of the spaces and commas in the filenames, then sort them and merge them, thus:

 find . -name "*" -type f | rename 's/ /_/g'
 find . -name "*" -type f | rename 's/,/_/g'
 ls | sort -n | pdfunite *.pdf merged.pdf

I would try to tune a sort command to match the required order:

qdf --empty --pages `ls *.pdf |sort -n` -- out.pdf

This approach will not work if filenames include spaces. In this case, I propose:

find . -name "*.pdf" -type f -print0  |sort -V -z |xargs -0 qpdf --empty --pages {} -- out.pdf

If this does not fill your needs, please explain the problems you find.

  • Thank you for your time and comment. Here is what I got: qpdf: error at * in numeric range * I edited the post with the examples of file names.
    – wodikiy313
    Commented Dec 5, 2022 at 18:22
  • 1
    This method is similar to Bash pitfall number 1, equally flawed. Commented Dec 5, 2022 at 18:47
  • qpdf: unknown argument ./1. Why to learn System and Network.pdf
    – wodikiy313
    Commented Dec 14, 2022 at 7:10

Not the answer you're looking for? Browse other questions tagged .