tar, gzip, bzip2, xz, zstd, zip, and 7z form the archive and compression toolkit that every Linux/Unix practitioner encounters daily — from packaging source releases to CI artifact caching to long-term backups. Unlike zip, which compresses each file independently, the tar-plus-compressor model first concatenates files into a single stream and then compresses the stream as a whole, yielding significantly better ratios on directories. The key mental model: tar handles structure and metadata; the compressor handles size — choosing the right compressor is a separate decision from choosing the archive format, and the two can always be swapped independently.
What This Cheat Sheet Covers
This topic spans 20 focused tables and 144 indexed concepts, 95 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Core tar Operations (Create, Extract, List, Append)
GNU tar's four primary operations — create, extract, list, and append — cover virtually every archiving workflow. The -f flag is positional: it must immediately precede the archive filename. Modern tar accepts options without a leading dash when they are the first argument (e.g., tar czf and tar -czf are both valid).
| Command | Example | Description | |
|---|---|---|---|
tar -cf archive.tar dir/ | • Creates a new archive • -c must not be combined with -x or -t. | ||
tar -xf archive.tar | Extracts all members to the current directory. | ||
tar -tf archive.tar | • Prints member names without extracting • pipe-friendly | ||
tar -cvf archive.tar dir/ | • Prints each file as it is processed • use twice ( -vv) for detailed listing similar to ls -l. | ||
tar -xf archive.tar -C /tmp/dest | • Changes to the given directory before extracting • created automatically if it exists | ||
tar -rf archive.tar newfile.txt | • Appends files to an uncompressed archive only • compressed archives cannot be appended | ||
tar -uf archive.tar dir/ | • Appends archive members newer than the existing copy • uncompressed archives only. | ||
tar -f archive.tar --delete oldfile.txt | Removes a member from an uncompressed archive without re-creating it. | ||
tar -cWf archive.tar dir/ | • Compares archive members against the file system immediately after writing • detects write errors | ||
tar -xf - | • Uses stdin as the archive source • enables pipe-based streaming | ||
find . -name '*.log' -print0 | tar --null -cf logs.tar --files-from=- | • Reads filenames from a file or stdin • --null handles names with spaces |