Compression
tar
Archive files into a tarball, with optional compression (gzip, bzip2, xz).
Synopsis
syntax
tar [OPTION]... [FILE]...
Examples
Create gzipped tarball of directory
tar -czf archive.tar.gz dir/
Extract gzipped tarball
tar -xzf archive.tar.gz
List contents without extracting
tar -tf archive.tar.gz
Create xz archive excluding .git
tar -cJf backup.tar.xz --exclude='.git' .
Extract to specific directory
tar -xzf archive.tar.gz -C /opt/
Common options
| Flag | Description |
|---|---|
| -c | Create new archive |
| -x | Extract from archive |
| -z | Filter through gzip |
| -j | Filter through bzip2 |
| -J | Filter through xz |
| -v | Verbose listing |
| -f | Specify archive filename |
| -t | List archive contents |
About tar
The `tar` command archive files into a tarball, with optional compression (gzip, bzip2, xz). Compression commands reduce file sizes for storage and transfer.
Linux supports multiple compression formats, each with different speed and ratio trade-offs. Understanding these tools is essential for working with archives, backups, log rotation, and software distribution packages.
The command accepts 8 commonly used flags shown above, though the full set of options is available in the man page (`man tar`). The 5 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.
Related commands
More Compression Commands
Other commands in the Compression category