This should work with file names containing spaces, newlines, apostrophes, and quotation marks (all this is possible on UNIX file systems):
find . -maxdepth 1 -type f -print0 | sort -zn | xargs -0 sh -c 'pdftk "$@" cat output combinewd2.pdf' "$0"
This may be redundant compared to the accepted answer if you know that you are working with simple file names.
But if you are writing a script that will be used again in the future, it is advisable that it does not explode one day when it encounters unusual (but valid) inputs.
This is basically an adaptation of the andrewdotn response, which interrupts input files with a zero byte rather than a newline, hence preserving the names of files that contain one or more newline characters.
The corresponding options -print0 , -z and -0 tell each program that I / O should be separated by a zero byte. Three different programs, three different arguments!
joeytwiddle
source share