Skip to content

Tar & Archives for Mere Mortals

Every backup, release, and log bundle you've ever touched was an archive: many files packed into one, usually shrunk on the way. This guide takes that file apart — how it's built, how to look inside before opening it, what comes back out the other side, and the ways an archive from a stranger can misbehave.

"Making an archive" is two jobs, not one. tar packs a tree into a single file, keeping its structure, permissions, and links. gzip (or bzip2, xz, zstd) shrinks a single stream of bytes. The .tar.gz you meet every day is the pipeline of both — and once that clicks, the rest of the subject is details. This guide covers the details with the receipts attached, including the chapter most archive guides skip: the extraction-safety one, where archives built to escape their directory are opened in a lab and the tools' refusals are quoted verbatim.

If you know this series' Backups guide: that one is the strategy — what to copy, how often, where to keep it. This one is the mechanics underneath it.

It assumes you can use a terminal and make folders. Everything archive-specific — modes, members, the leading-slash rule, setuid bits — is explained from zero.

What this guide covers

What it doesn't cover

Backup strategy and tools (the Backups guide owns that: restic, Borg, the 3-2-1 rule), encryption — an archive is packed, not sealed, and zip's legacy password option is not protection; see the OpenSSL guide for the real machinery — and incremental-backup systems. Tape drives are tar's birthplace and are mentioned only there.

How to use this guide

Everything was run for real with GNU tar 1.35, gzip 1.12, xz 5.4.5, bzip2 1.0.8, zstd 1.5.5, and Info-ZIP zip 3.0 / unzip 6.00, against a fixture corpus the shipped examples/make-corpus.sh rebuilds exactly: forty small notes, three generated logs, and one file of random bytes that no compressor can shrink. Every size and time in the compression chapter is that corpus on that machine, and the chapters say so. Two things the build machine would not do are flagged where they belong: its kernel refuses chown() even for root (so root extractions here complain about ownership while the modes land exactly as captured — chapter 9 explains), and its sandbox resets ssh sessions, so tar-over-ssh is written as the local pipe's identical shape and marked (documented). criteria.md keeps the full ledger.

Fixture rebuild safety

The fixture builder creates a new target directory. It replaces an existing target only when that directory carries this guide's completed-build ownership marker (.mere-mortals-fixture). Existing unmarked directories, symlink targets, protected home/current/script directories and overlapping builds are refused. Older fixture trees have no marker: use a fresh directory name and inspect the old tree manually. Do not add a marker to an unrelated directory. A failed or interrupted build may leave an unmarked tree or stale .build-lock directory; inspect it before cleaning up.


Part of the series

This guide is one of the For Mere Mortals guides: plain-language guides to the tools programmers and makers use.

Related guides:

License

The writing in this guide is licensed under CC BY 4.0. Code examples and lab scripts are licensed under the MIT License.