Ghostscript is a very useful tool in this situation

sudo apt install -yq ghostscript
# To extract pages between 3 to 5 from in.pdf to out.pdf
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=3 -dLastPage=5 -sOutputFile=out.pdf in.pdf
# Skip -dFirstPage or -dLastPage to extract "from begin", "until end" respectively
# To combine 2 pdf files
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=out.pdf in1.pdf in2.pdf