I know of 2 possibilities to merge pdf files:
$ gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \ -sOutputFile=mergedPDF.pdf file1.pdf file2.pdf file3.pdf
Pdftk can do various things with PDF files, e.g. merge, split, decrypt, encrypt, recompress, repair.
To merge files use:
$ pdftk file1.pdf file2.pdf cat output out.pdf
Actually my favorite solution is pdftk. With ghostscript I had often problems with huge memory consumption and program aborts while merging even small pdf files. pdftk seems to handl pdfs more intelligent.