Archives & Compression

Intermediate

Overview

tar packs many files into a single archive (a 'tarball'). On its own it does not compress — it is usually combined with gzip via the z flag.

The common flags spell out the action: c = create, x = extract, t = list, v = verbose, f = file, z = gzip. So tar -czf makes a compressed archive and tar -xzf extracts one.

Remember -f must come last because it expects the archive filename right after it.

Cheatsheet

tar -czf out.tar.gz dir/Create a gzipped archive
tar -xzf out.tar.gzExtract a gzipped archive
tar -tzf out.tar.gzList archive contents
gzip fileCompress a single file to file.gz
gunzip file.gzDecompress a .gz file

Try it

A safe, simulated terminal. Run the suggested commands to see typical output.

simulated terminal

Type a command and press Enter, or click a suggestion below to run it.

$

Quick quiz

1. Which tar command creates a gzip-compressed archive?

2. What does the z flag add to a tar command?