How to Compress/Uncompress Files in Linux Using gzip, bzip2, 7z, rar and zip
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 -r --best -c dir > ./dir.gzUncompress
tar -c dir | bzip2 --best -c > ./dir.tar.bz2Uncompress
tar xf ./dir.tar.bz2
7za -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on a ./dir.7z dirUncompress
7za x ./dir.7z
rar -m5 a ./dir.rar dirUncompress
rar x ./dir.rar
zip -r -9 ./dir.zip dirUncompress
unzip ./dir.zipWe can delete the options in black fonts for faster compressing and shorter command line instead of best compressing rate.