GREPWISE

Remember tar flags for good (a mnemonic)

Remember tar as c/t/x plus z and f. Create, list, and extract one archive and the flags stop feeling random.

c creates, t lists, x extracts. That is the whole mnemonic.

Most tar mistakes are not technical. You just forget whether this time was create, list, or extract, then shuffle letters until the archive opens.

Use the mnemonic: create, table of contents, extract. Add z for gzip, f for file.

tmp=$(mktemp -d); mkdir -p "$tmp/demo" && printf 'alpha\n' > "$tmp/demo/a.txt" && printf 'beta\n' > "$tmp/demo/b.txt"
cd "$tmp" && tar -czf demo.tgz demo                              # create gzip archive file
tar -tzf demo.tgz                                                 # list contents
mkdir out && tar -xzf demo.tgz -C out                             # extract into out/
[list]
demo/
demo/b.txt
demo/a.txt
[extracted]
out/demo/a.txt: alpha
out/demo/b.txt: beta

Once the letters map to verbs, the order stops being mystical. czf builds an archive. tzf inspects it. xzf unpacks it.

Say the verbs once before you type the flags.

#tar#bash#linux#selfhosting

❯ exit 0

cd ..