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.
Table of Contents
gzip -r --best -c dir > ./dir.gz
tar xf ./dir.tar.bz2
7za -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on a ./dir.7z dir
7za x ./dir.7z
rar -m5 a ./dir.rar dir
rar x ./dir.rar
zip -r -9 ./dir.zip dir
We can delete the options in black fonts for faster compressing and shorter command line instead of best compressing rate.