Linux: Create tar zip gzip bzip2 xz zip 7z rar

By Xah Lee. Date: .

tar archive (.tar)

“tar” is for making a directory into a single file. Tar does not compress. Tar is often used with a compression utility such as gzip.

archive a folder
tar cvf newName.tar dirName

Here's most frequently used options:

  • v → verbose, meaning print out status.
  • f → file.
  • c → create.
  • x → extract.
  • t → test/list content.

“tar” can untar and decompress in one step:

Extract .tar
tar xvf fileName
Extract .tar.gz
tar xvfz fileName
Extract .bz2
tar xvfj fileName
Extract .xz
tar xvfJ fileName
List content of .tar
tar -tvf fileName

gzip compression (.gz)

gzip is for compressing a single file.

Compress
gzip fileName
Decompress
gzip -d fileName or gunzip fileName

bzip2 compression (.bz2)

bzip2 is for compressing a single file.

Compress
bzip2 fileName
Decompress
bzip2 -d fileName

xz compression (.xz)

xz is for compressing a single file.

Compress
xz fileName
Decompress
unxz fileName or xz -d fileName

zip archive (.zip)

ZIP (file format) is for archiving and compressing a folder or single file.

Create archive
zip -r newName.zip dirName
Extract
unzip fileName
Check integrity
zip -T name.zip

7-zip archive (.7z)

7-zip is for archiving and compressing a folder.

The 7z util can decompress many formats.

Create archive
7z a -t7z newName.7z dirName
Extract
7z x fileName

rar archive (.rar .rev .r00 .r01 .r02 …)

RAR (file format) is for archiving and compressing a folder. File extension: {.rar .rev .r00 .r01 .r02 …}.

Extract rar file
unrar e fileName
Extract rar file
7z x fileName

Compression File Size Comparison

Linux Compress, Archive, Download