Archiving and compression — tar, zip, and why .tar.gz is everywhere
'Archiving' (bundling many files into one) and 'compression' (making that bundle smaller) are two separate steps that most tools do together — which is exactly why a filename like project.tar.gz has two extensions, not one.
Beginner
2 min read
Two separate jobs, usually done together
Archiving means combining many files and directories into a single file,
preserving their structure — useful even with zero compression, since moving
or emailing one file is simpler than moving a thousand. Compression means
shrinking that data's size using an algorithm that finds and removes
redundancy. They're conceptually separate, but the tools you'll actually use
almost always do both at once.
tar: the archiving tool, and why its flags look cryptic
tar ("tape archive," a name from actual magnetic tape backups decades ago)
is the standard Linux archiving tool:
# Create an archive (c = create, v = verbose/list files, f = filename)$ tar -cvf project.tar project/# Extract an archive (x = extract)$ tar -xvf project.tar# Create a COMPRESSED archive (z = also gzip-compress)$ tar -czvf project.tar.gz project/# Extract a compressed .tar.gz archive$ tar -xzvf project.tar.gz
The z flag is the whole reason .tar.gz shows up everywhere: tar bundles
the files first, then pipes that bundle through gzip compression in the
same command — which is also exactly why the extension is two parts stacked
together, .tar (archived) then .gz (compressed), not one combined format.
zip: the cross-platform alternative
zip bundles and compresses in one native format (no separate compression
flag needed), and — unlike a plain .tar.gz — a .zip file can be extracted
natively on Windows and macOS without any extra tooling, which is why it's
the more common choice for anything being shared outside a Linux/Unix
environment:
$ zip -r project.zip project/$ unzip project.zip
Why this matters day to day
Recognizing -czvf on sight (create, compress, verbose, filename) and
knowing x extracts instead of creates saves a trip to search "how to
unzip tar.gz" every single time it comes up — a genuinely common task in
software engineering, from downloading a source release to preparing a
deployment bundle to backing up a config directory before making a risky
change.