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. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
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 |