Files
my-docs/Linux/Basic Administration/11-tar.md
2025-11-09 11:11:43 +03:30

2.3 KiB

Linux Compression & Archiving Cheatsheet

Tar Command Basics

The tar command is used to create, extract, and manage archive files.

Syntax:

tar [options] [archive_name.tar] [file(s)/directory]

Create a .tar Archive

tar -cf archive_file.tar file1 file2 dir1

Options:

  • -c: Create a new archive
  • -f: Specify the archive file name

Create with Verbose Output

tar -cvf archive_file.tar file1 file2 dir1
  • -v: Verbose mode (shows progress)

Extract a .tar Archive

tar -xf archive_file.tar

or

tar -xvf archive_file.tar
  • -x: Extract files

Gzip Compression

Gzip (GNU zip) is a fast and widely used compression tool.

Create a .tar.gz Archive

tar -czf archive_file.tar.gz file1 file2 dir1
  • -z: Compress using gzip

Verbose Creation

tar -czvf archive_file.tar.gz file1 file2 dir1

Extract .tar.gz

tar -xzf archive_file.tar.gz

or

tar -xzvf archive_file.tar.gz

Bzip2 Compression

Bzip2 provides better compression than gzip but at the cost of speed.

Create a .tar.bz2 Archive

tar -cjf archive_file.tar.bz2 file1 file2 dir1
  • -j: Compress using bzip2

Verbose Creation

tar -cjvf archive_file.tar.bz2 file1 file2 dir1

Extract .tar.bz2

tar -xjf archive_file.tar.bz2

or

tar -xjvf archive_file.tar.bz2

XZ Compression

XZ offers the best compression ratio but is the slowest option.

Create a .tar.xz Archive

tar -cJf archive_file.tar.xz file1 file2 dir1
  • -J: Compress using xz

Verbose Creation

tar -cJvf archive_file.tar.xz file1 file2 dir1

Extract .tar.xz

tar -xJf archive_file.tar.xz

or

tar -xJvf archive_file.tar.xz

Compression Format Comparison

Feature gzip bzip2 xz
Compression Speed Fast Slow Slowest
Decompression Speed Fast Slower Moderate
Compression Ratio Good Better Best
File Extension .tar.gz .tar.bz2 .tar.xz
Common Use General/Web Backups Archival