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 archivetar -xzf out.tar.gzExtract a gzipped archivetar -tzf out.tar.gzList archive contentsgzip fileCompress a single file to file.gzgunzip file.gzDecompress a .gz fileTry 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?