#!/bin/bash FILE=$1 PAGES=`pdfinfo ${FILE} | awk '/^Pages:/ {print $2}'` pdftk ${FILE} cat ${PAGES} 1-$(( ${PAGES}-1)) output ${FILE}_resorted.pdf