I'd like to concatenate all PDFs in subdirectories, with filenames potentially containing whitespaces. I am well aware of this solution,

find . -name *.pdf -print0 | xargs -0 -J FILE  pdftk FILE cat output out.pdf

However, my xargs version does not support the -J option, unfortunately. Are there alternative ways to achieve this?

I've tried this

pdftk $(find . -name *.pdf -print0 | xargs -0  -I {} printf '%q ' {}  ) cat output out.pdf

but pdftk treats this as if the escapes weren't there.


-I is not the right option for you. What you need is the following:

find . -name '*.pdf' -type f -exec sh -c 'pdftk "$@" cat output /tmp/out.pdf' x {} +

A few disclaimers are in order here:

a) Your current working dir. != /tmp
b) The sh is run just once otw, the out.pdf will be overwritten by the last run.
c) Your sh stores the 1st -> $0, 2nd -> $1, 3rd -> $2, etc.

Although all the above can be worked around but this is enough to get you started.

Your Answer

