This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

tar Cheatsheet

Quick reference guide for the UNIX tar command, covering archiving, gzip and bzip2 compression, unpacking, and listing contents.

· Published

The tar utility archives, bundles, and extracts file trees on Linux and Unix systems.

Common Operations

Compress and Archive

# Create gzip-compressed archive (.tar.gz)
tar -czf archive.tar.gz /path/to/files

# Create uncompressed archive (.tar)
tar -cf archive.tar /path/to/files

# Create bzip2-compressed archive (.tar.bz2)
tar -cjf archive.tar.bz2 /path/to/files

Extract Archive

# Extract gzip-compressed archive in current directory
tar -xzf archive.tar.gz

# Extract archive to a target directory
tar -xzf archive.tar.gz -C /target/directory

# Extract plain tar archive
tar -xf archive.tar

List and Inspect

# List archive contents without extracting
tar -tzf archive.tar.gz

# List archive contents verbosely with details
tar -tvzf archive.tar.gz

Append Files

# Append file to existing uncompressed archive
tar -rf archive.tar new_file.txt

# Update files newer than archive copy
tar -uf archive.tar changed_file.txt

Option Flags Reference

Flag Name Description
-c --create Create a new archive
-x --extract Extract files from an archive
-t --list List table of contents
-z --gzip Filter archive through gzip
-j --bzip2 Filter archive through bzip2
-f --file Use specified archive file name
-v --verbose Verbosely list processed files
-C --directory Change to target directory before operations
-u --update Only append files that are newer than archive copy

Related topics