Cheatsheet: Tar
Last updated 2026-09-21
Basic Archiving Commands
Create an archive from a directory
Create a compressed archive using gzip
Create a compressed archive using bzip2
Create an archive from multiple files
Create an archive without baking in the full source path (cd into the dir first with -C, archive '.')
Create an archive while excluding matching files (e.g. skip logs)
Extracting Archives
Extract a tar archive
Extract a gzip-compressed tar archive
Extract a bzip2-compressed tar archive
Extract to a specific directory
Extract only one specific file from the archive
Extract files matching a glob pattern (needs --wildcards, GNU tar)
Listing & Verifying Archive Contents
List the contents of an archive
List the contents of a gzip-compressed archive
List the contents of a bzip2-compressed archive
Count how many entries an archive contains, without extracting
Compare an already-extracted archive's files against what's on disk (real content check, unlike -t)
Advanced Options
Add files to an existing uncompressed archive (append doesn't work on .tar.gz/.tar.bz2)
Delete a file from an archive (use with caution)
Create an archive and split it into multiple parts
Extract a single file from an archive