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
Compressgzip -r --best -c dir > ./dir.gzUncompress
unzip ./dir.gz
bzip2
Compresstar -c dir | bzip2 --best -c > ./dir.tar.bz2Uncompress
tar xf ./dir.tar.bz2
7z
Compress7za -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on a ./dir.7z dirUncompress
7za x ./dir.7z
RAR
Compressrar -m5 a ./dir.rar dirUncompress
rar x ./dir.rar
ZIP
Compresszip -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.
By: Zhiqiang Ma
Last updated: Nov 28, 2012
Views: 10,715
Tags: Command line, Fedora, shell, Tutorial
Tags: Command line, Fedora, shell, Tutorial
tar -c dir | bzip2 –best -c dir > ./dir.tar.bz2
=>
tar -c dir | bzip2 –best -c > ./dir.tar.bz2