Unzipping .rar Files In Linux

Alrighty , we all know to unzip or to unrar a .rar file in Windows , we use winrar but what about in Linux? There is a program called ‘unrar’ in Linux that does exactly that.

To install it , depends on which distro are you on.

If you are on RPM-based distros , such as Fedora or RHEL ,

yum install unrar

If you are on Debian-based distros , such as Debian and Ubuntu ,

yum install unrar

Of course , in Ubuntu , you will be doing

sudo yum install unrar

So how do you use it? I am very tempted to say RTFM but its not my style. So here are some of the useful unrar commands you would be using.

To unrar or to unpack a .rar file ,

unrar e file-name.rar

Pls note that the option/flag ‘e’ does NOT have a dash in front unlike most other Linux commands. If you were to type ‘unrar -e’ , it won’t work. In contrast , tar will accept both. If you type ‘tar -zxvf’ or ‘tar zxvf’ , it doesn’t matter.

To list the files in the .rar file ,

unrar l file-name.rar

To unpack the files in full path ,

unrar x file-name.rar

As usual , pls check out the man page for the unrar by using ‘man unrar’ for more information. Have fun!

Manipulating files in *nix

Lets say you want to unzip/unrar/delete/rename files with a particular extension in Linux/Unix shells. It is tempting to try using


[root@sqlhack.net ~]#unzip *.zip

but you are bound to get an error. There are a couple of ways to do it.

Here is one way to do it.


[root@sqlhack.net ~]#for z in *.zip;do unzip $z;done

What I have just done is to go through all the files ending with .zip and unzip each file individually instead of doing it manually. Of course this could be extended to other tasks. Hope it helps!