Docs / Linux Basics / How to Use tar to Archive and Compress Files

How to Use tar to Archive and Compress Files

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 389 views · 1 min read

tar is the standard tool for creating and extracting archives on Linux.

Create an Archive

# Create gzip compressed archive
tar -czf archive.tar.gz /path/to/directory

# Create bzip2 compressed archive
tar -cjf archive.tar.bz2 /path/to/directory

Extract an Archive

# Extract gzip archive
tar -xzf archive.tar.gz

# Extract to specific directory
tar -xzf archive.tar.gz -C /destination/

List Contents

tar -tzf archive.tar.gz

Common Flags

  • -c — create
  • -x — extract
  • -z — gzip compression
  • -j — bzip2 compression
  • -f — specify filename
  • -v — verbose (show files)
  • -t — list contents

Was this article helpful?