Linux: Compression How-to: tar gzip bzip2 xz 7zip rar zip
This page shows you how to decompress or compress file or directory in Linux.
untar, unzip, ungzip, unbzip2, unxz
tar xvf fileName.tar
- Untar
unzip fileName
- Unzip
gzip -d fileName
- Decompress gzip
bzip2 -d fileName
- Decompress bzip2
xz -d fileName
- Decompress xz
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 unix standard for compressing a single file.
- Compress
gzip fileName
- Decompress
gzip -d fileName
orgunzip fileName
- Check integrity
gzip -t 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
orxz -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
- emacs-24.2.tar.gz 49M
- emacs-24.2.tar.bz2 40M
- emacs-24.2.tar.xz 33M