If you have been using linux for a few days, you see that it's almost impossible to go by without seeing a compress file. Here are the basic rules on how to decompress .zip, .gz .tar / .tar.gz / .tar.bz2 .rar files
The zip format is pretty much straite forward. No fancy flags, simply the command and the file(s) to unzip
unzip somefile.zip
Gzip format was develop as a GNU project. It was created to replace the compress program in the unix systems. As zip, you don't need any fancy flags.
gunzip somefile.gz
You might encounter some
tarball will you search for datasets. These are basically a combination of the tar compression then compress using gzip. Here are two ways to decompress them.
gunzip < file.tar.gz | tar xvf -$ gunzip < file.tgz | tar xvf -
or simpler
tar xvzf file.tar.gz
It is good to notice that tar can be combine with other things compression method like bzip2, xz, lzip, lzma and compress.
With a tar.bz2, you will need to replace the
z flag used earlier with the
j flag.
tar xvjf file.tar.bz2
Now everyone has a friends that just know how to use WinRar on Windows OS and refuse to change compression method. So this is how you could extract those rar files in your Linux machine.
First install unrar.
sudo apt-get install unrar (Debian like distros)
sudo yum install unrar (CentOs like distros)
sudo pacman -S unrar (Archlinux like distros)
And to extract add the
e flag
unrar e somefile.rar
Sources
- About Tech - Practical Examples For The Linux Unzip Command
- nixCraft - Linux / UNIX command to open .gz files
- nixCraft - Linux: tar Extract Files
- nixCraft - Open RAR File / Extract RAR Files Under Linux or UNIX
- Wikipedia - Gzip
- Wikipedia - Tar (computing)