kmail.at
contact

elsewhere

EnglishEN
← learning

linux · difficulty ◆◆

tar — archive and compress files

Pack everything into one file, then unpack it anywhere.

tar was born to write data to magnetic tape in 1979. Half a century later it still ships the world's source code — and most people only ever learn two of its incantations.

fully AI-generatedThis text is fully AI-generated and was published without human editorial review.

2026-08-12 · 6 min read

$ tar
1.35
version here

GNU tar 1.35

1979
created

Bell Labs, for tape

tape archive
name means

the original use

c x t f
flag core

create, extract, list, file

What it does

tar combines multiple files and directories into a single archive file, and can optionally compress it with gzip, bzip2, or xz. The name stands for 'tape archive' — it was originally written to back up data to magnetic tape.

Why it matters

tar is the default way Unix systems move and back up whole trees of files. Combined with a compressor, it shrinks a directory into one portable file you can copy, email, or ship to a server.

Example

$ tar -czf backup.tar.gz src/
(no output — archive created)
$ ls -lh backup.tar.gz
-rw-r--r-- 1 kmail kmail 4.2M Aug 12 09:00 backup.tar.gz

-c create, -z gzip, -f file. Packs src/ into backup.tar.gz.

$ tar -xzf backup.tar.gz
$ ls
src/  backup.tar.gz

-x extract, -z gzip, -f file. Restores the archive into the current directory.

Common flags

-c
create a new archive
-x
extract files from an archive
-z
filter through gzip (compress/extract .tar.gz)
-f
use an archive file (required before a filename)
-v
verbose — list each file as it is processed
-t
list the contents of an archive

History

Origin

tar was developed in 1979 at Bell Labs for backing up to tape drives, which is why its flags (c, x, f) read like tape operations. It predates the common gzip/jbzip compression, which were layered on later.

Fun fact

Despite its age, tar remains the standard for distributing software source code (the .tar.gz 'tarball') — and GNU tar is so foundational it ships on every Linux distribution by default.

Under the hood

Why "tape archive" still matters

tar originally concatenated files into one stream for sequential tape drives, which is why it preserves file metadata but does no compression of its own. The format survived because a single .tar file keeps permissions, ownership, and directory structure intact — the properties you need for real backups and distribution.

Compression is layered on top

The -z flag pipes the archive through gzip (or its alias) rather than doing compression internally. That is why you can use -j for bzip2, -J for xz, or omit it entirely for an uncompressed .tar. Modern GNU tar can even auto-detect the compression on extraction with just -x.

Fun facts

Pros & cons

pros

  • + Preserves permissions, ownership, and directory structure exactly
  • + Universal — every Unix-like system ships it
  • + Compression is optional and swappable (-z, -j, -J)
  • + Streams, so you can pipe archives between machines without a temp file

cons

  • − Does not compress by itself; you must pair it with a compressor
  • − Classic flag syntax is easy to misremember
  • − Not ideal for incremental backups without extra tooling (--listed-incremental)
  • − A single corrupt block can hurt the whole archive (mitigate with gzip integrity checks)

Takeaways

  1. 1Create: `tar -czf archive.tar.gz dir/`
  2. 2Extract: `tar -xzf archive.tar.gz`
  3. 3Inspect: `tar -tzf archive.tar.gz` lists contents without extracting
  4. 4Pipe across the network: `tar -czf - dir/ | ssh host "cat > backup.tgz"`
  5. 5For incremental or encrypted backups, reach for restic or borg instead

Related commands

archive entry — written and published by a scheduled job, never editorially reviewed. Kept for reference: out of the site’s search index, and no ads run here. the reviewed library →

← all learning