CS - Unix, Shell, and alike

Terminal
Shell
A personal cheat sheet of Unix / macOS terminal commands, shortcuts and workflows.
Published

July 22, 2026

A personal collection of terminal commands, keyboard shortcuts and small workflows I keep coming back to on Unix and macOS.

Terminal — useful commands

Command What it does
diff -w file1 file2 > diff.txt Compare two files ignoring whitespace and save the differences to a file.
open -a Application file macOS: open a file with a specific application.
echo -e "first_line\nsecond_line" Print text interpreting escape sequences such as \n (newline); -e enables them.
ssh -v user@gateway -t ssh user@internal Verbose SSH that jumps through a gateway/firewall host to reach an internal host.
sshfs user@host:/remote/dir /local/dir Mount a remote directory over SSH as if it were a local folder.
screen -S name Start a named, detachable terminal session that keeps running in the background.
curl "url" -O Download/transfer data from a URL (the Unix counterpart to wget); -O saves it to a file.
echo "hello, world!" | tee file.txt Print to the screen and write the same output to a file at once.
iconv -f utf-8 -t iso-8859-1 in.txt > out.txt Convert a text file from one character encoding to another.
file -I filename Show a file’s type and character encoding (-I on macOS, -i on GNU/Linux).
nmap -n -sn 10.0.0.0/24 Ping-scan a subnet to discover live hosts (-sn; the old -sP is deprecated).
top -d seconds Monitor running processes, refreshing every N seconds.
awk '{print FNR "\t" $0}' file.txt | open -f Prepend pseudo line numbers and open the result in TextEdit (macOS; use ⌥+drag for column selection).

Terminal — keyboard shortcuts

These are the default Emacs-style line-editing bindings in bash/zsh.

Shortcut Action
Ctrl + A Move to the beginning of the line.
Ctrl + E Move to the end of the line.
Ctrl + U Delete from the cursor back to the beginning of the line.
Ctrl + K Delete from the cursor to the end of the line.
Ctrl + W Delete the word before the cursor.
Ctrl + Y Paste (yank) the text that was just deleted.
Ctrl + C Cancel / interrupt the current command.
Ctrl + L Clear the screen.
Ctrl + R Reverse-search command history; press again to step through matches.

screen shortcuts

Shortcut Action
Ctrl + A, then D Detach from the current screen session (it keeps running).
Ctrl + A, then [ Enter scrollback / copy mode.

Sun Grid Engine essentials

Basic job-scheduling commands on a Sun Grid Engine (SGE) cluster.

Command What it does
qsub script.sh Submit a job to the queue.
qdel jobid Delete/cancel a job; qdel -u user cancels all of a user’s jobs.
qstat -f Show the full status of queues and jobs.
qstat -j jobid Show detailed information about a specific job.
qstat -explain c Explain why a queue/job is in a given state.
qstat -F attribute List queues filtered by resource attributes.
qhost -j List cluster hosts together with the jobs running on them.

macOS — fast symbols with the Option key

Hold ⌥ Option and press a key (US keyboard layout). Entries marked (dead key) combine with the next character you type — e.g. +e then a gives á.

Keys Symbols
+ 1 2 3 4 5 6 7 8 9 0 ¡ ™ £ ¢ ∞ § ¶ • ª º
+ q w e r t y u i o p œ ∑ ´ ® † ¥ ¨ ˆ ø π
+ a s d f g h j k l å ß ∂ ƒ © ˙ ∆ ˚ ¬
+ z x c v b n m Ω ≈ ç √ ∫ ˜ µ
+ =
+ [ ] \ ” ’ «
+ ; ' … æ
+ , . / ≤ ≥ ÷

Combine with Shift for a second set of symbols:

Keys Symbol
+ Shift + K Apple logo ()
+ Shift + 2
+ Shift + 8 °
+ Shift + V

Dead keys: +e = acute (´), +u = umlaut (¨), +i = circumflex (ˆ), +n = tilde (˜).

Miscellaneous workflows

Record a voice-over with say

macOS can read a text file aloud and save it as audio:

say -f file.txt -o output.aiff -r <words_per_minute> -v <voice>

-v picks a voice (e.g. Alex, Bruce, Luciana). List installed voices with say -v '?'.

.zshrc and .zshenv

macOS uses Z shell as the default shell.

  • Put your preferences in ~/.zshrc, then reload them with source ~/.zshrc.
  • If you already have a .bash_profile, the quickest way to keep things working is to source it from a .zshenv:
echo 'source ~/.bash_profile' > ~/.zshenv && source ~/.zshenv

See this discussion.

Convert image files in batch

Replace FORMAT with png, jpeg or tiff and EXT with the matching extension (EPS may not work):

for i in *; do sips -s format FORMAT "$i" --out "${i%.*}.EXT"; done

Or with ImageMagick:

brew install imagemagick
magick A.jpg A.png   # `magick convert` on older ImageMagick 6

Create a password-protected ZIP file

zip -er file.zip folder_to_zip/

-e encrypts the archive (prompts for a password); -r adds the folder recursively.

Install Jekyll on Apple silicon (M1/M2)

Jekyll is a solid backend for static sites, but on Apple silicon the system Ruby can cause architecture problems. A reliable workaround:

  • Don’t use the Ruby bundled with macOS — install it from Homebrew, following the official steps.
  • Homebrew’s Ruby is keg-only and not symlinked, so add it (and the gem executables) to ~/.zshenv:
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
export PATH="$HOME/.gem/ruby/3.1.0/bin:$PATH"
  • Restart the shell and confirm ruby -v points to the Homebrew version.
  • Install jekyll, bundler and webrick (the last one is required) locally:
gem install --user-install bundler jekyll webrick

Convert .m4a to .mp3

brew install ffmpeg
ffmpeg -i in.m4a -codec:a libmp3lame -qscale:a 1 out.mp3

Remove printing restrictions from a PDF

brew install qpdf
qpdf --decrypt in.pdf out.pdf

Convert a PDF to plain text

brew install xpdf
pdftotext -enc UTF-8 in.pdf out.txt

Merge PDFs from the command line

Use pdfunite (part of Poppler). It may conflict with xpdf, since both depend on Poppler:

pdfunite in1.pdf in2.pdf merged.pdf
Back to top