Command line tricks for college
The command line can save you a lot of time in college. Here are some common problems outside of a computer science course that powerful CLI tools can tackle.
All of the tools I’m linking here can be easily installed via Homebrew on macOS. Before I started using a MacBook, I used these same tools on Arch Linux.
Fix bad PDFs🔗
On countless occasions I had to deal with PDFs whose pages were skewed, grainy, rotated, and/or not Ctrl-F friendly. You can rotate the PDF in the browser, but what if the pages are rotated in all sorts of directions? What if you want to search for text in the document, but you can’t? When trying to fix these issues, a lot of people will head for Adobe Acrobat. There’s nothing inherently wrong about this, but Acrobat isn’t always available with your university’s software license program, nor is it particularly fast or intuitive.
ocrmypdf adds an OCR text layer to PDFs that will let you search, highlight, and copy-and-paste content as you would expect from a good PDF. It can also de-skew and rotate your pages into an upright position.
This command takes
bad.pdf and produces
$ ocrmypdf --rotate-pages --deskew bad.pdf good.pdf
pdfunite combines multiple PDFs into a single file. This is particularly useful when you’re reviewing lecture slides in preparation for an upcoming exam, and don’t want to juggle browser tabs.
For instance, let’s say I have six PDFs that each cover a single chapter’s worth of content. I’ll combine them like so:
$ pdfunite 1.pdf 2.pdf 3.pdf 4.pdf 5.pdf 6.pdf review.pdf
…and just open up
review.pdf in my browser to study.
Turn stuff into PDFs🔗
Have you ever expected to be provided with a PDF for something, only to discover that your professor has instead issued you a PowerPoint
.pptx or Word
.docx file? Avoid having to wait for those Office splash screens and just convert those documents into a PDF.
$ soffice --headless --convert-to pdf lecture-notes.pptx
You’ll need to install LibreOffice (Homebrew) to use
Transfer between computers🔗
croc is a tool that lets you send files to any other computer that has
croc installed.1 All your recipient needs to do is type in a specific phrase from their terminal to receive your file. This is vastly easier and faster than using
rsync, because such tools become largely obsolete if the clients are on separate networks. Plus,
croc is also encrypted so you can rely on the same sense of security. You can think of
croc like a kind of cross-platform AirDrop built for the command line.
What you do to send
$ croc send cat.jpg Sending 'cat.jpg' (1.1 kB) Code is: 3750-alibi-memo-local On the other computer run croc 3750-alibi-memo-local Sending (->18.104.22.168:56112) 100% |████████████████████| (1.1/1.1 kB, 926.589 kB/s)
What your friend does to receive
$ croc 3750-alibi-memo-local Accept 'cat.jpg' (1.1 kB)? (Y/n) Receiving (<-321.321.321.321:58681) 100% |████████████████████| (1.1/1.1 kB, 21.985 kB/s)
Delete stuff safely🔗
We all invariably use
rm -rf recklessly sometimes. Because of the inherent danger of wielding
rm in situations where you only really mean to delete a small image or text file, it is far safer to use
$ trash temp.txt
In this example,
temp.txt will be moved to trash, where you can always restore it later if needed.
See Homebrew or Linux links for installation instructions
Pretend to be busy🔗
genact is for you. This hasn’t really saved me time; it’s just for fun.
You might have heard of croc’s better known alternative Magic Wormhole. I used to use Magic Wormhole instead of croc, but I found that croc was overall the better choice. Croc is written in Go, so it doesn’t have any Python dependencies like Magic Wormhole. It supports pause/resume, folder transfers without first converting the folder into a zipfile, and relay-less transfers. I also find that croc is generally faster on my machines.