Useful command line tools for uni
This blog post is a collection of useful (Linux) tools for PDFs, like slides or problem sheets at university. For every use case I give one example that should make the usage clear. Make sure to have the tools installed.
Concatenate two or more PDFs:
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combine.pdf -dBATCH 1.pdf 2.pdf 3.pdf n.pdf
Concatenate all PDFs in the current folder (the output goes to the parent folder, otherwise a second run would include combine.pdf in *.pdf):
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=../combine.pdf -dBATCH *.pdf > /dev/null
JPEGs to PDF:
img2pdf *.jpg -o submission.pdf
Add white margins to a PDF. Negative values add margins, positive values remove them:
pdfjam --fitpaper true --trim "-2cm 0cm -4cm 0cm" somepdf.pdf -o somepdf_margin.pdf
Download all PDFs from a website:
wget -r -A '*.pdf' https://example.com
If you are looking for a more advanced download tool that supports Ilias, among other sites, take a look at PFERD. It is written by fellow students and a huge time saver.
Collapse a folder structure (e.g., one created by the previous command):
find somefolder/ -type f -exec mv -t somefolder/ -i '{}' +
Remove line breaks and hyphenation from the clipboard (e.g., when copying text from PDFs):
xclip -o -sel clip | sed ':a;N;$!ba;s/-\n\([a-z]\)/\1/g;s/\n/ /g' | xclip -sel clip
To search in all notes (PDFs, plain text, images, etc.), take a look at ripgrep-all. If you want a more lightweight tool that just greps PDFs, pdfgrep will do the job.
Get cheat sheets for almost any tool by appending the tool name to cheat.sh:
curl cheat.sh/"gs"