How to Compress/Uncompress Files in Linux Using gzip, bzip2, 7z, rar and zip

By Zhiqiang Ma On Nov 28, 2012

Compress/uncompress files are frequent operations. The normal tools for compressing/uncompressing in Linux is gzip, bzip2, 7z, rar and zip. This post introduces how to compress and uncompress file in Linux using these tools. We use best compressing rate with all these tools and mark the options for “best rate” in bold fonts. We can delete these options if we don’t so care about the size of the compressed file and want a faster compressing.

The example we use here is to compress a directory dir recursively into a compressed file with particular file extension which specifies the compressing method.

gzip

Compress
gzip -r --best -c dir > ./dir.gz
Uncompress
unzip ./dir.gz

bzip2

Compress
tar -c dir | bzip2 --best -c > ./dir.tar.bz2
Uncompress
tar xf ./dir.tar.bz2

7z

Compress
7za -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on a ./dir.7z dir
Uncompress
7za x ./dir.7z

RAR

Compress
rar -m5 a ./dir.rar dir
Uncompress
rar x ./dir.rar

ZIP

Compress
zip -r -9 ./dir.zip dir
Uncompress
unzip ./dir.zip
We can delete the options in black fonts for faster compressing and shorter command line instead of best compressing rate.

By: Zhiqiang Ma Last updated: Nov 28, 2012 Views: 10,715
Tags: , , ,

About Zhiqiang Ma

Zhiqiang Ma is a PhD candidate at Dep. of CSE, HKUST. He is interested in system software for cloud computing, virtualization of large-scale distributed system, etc. Find Zhiqiang on Facebook, Twitter, LinkedIn and Google+.

One Comment to How to Compress/Uncompress Files in Linux Using gzip, bzip2, 7z, rar and zip | Add Comment
Add your comments, share your thoughts

Be nice. Keep it clean. Stay on topic. No spam.