Posted: . At: 9:41 PM. This was 5 years ago. Post ID: 12851
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to unpack a rar file on Linux with the command line interface.


Firstly, install unrar on Linux with this command.

sudo apt-get install unrar

Then unpack a rar file with this simple one-liner.

unrar x myfile.rar

Another way to compress files on Linux is to use the supplied utilities like tar and gzip. The tar utility packs all files into one archive, then this can be compressed with gzip.

Here is an example, creating a nice tar archive to later compress with gzip.

deusexmachina:stuff jason$ tar -cvf images.tar *.*
a 1514877771595.jpg
a 1538995576940.png
a 8c9ec9b3d45be9f9c880e850861a5fc7.jpg
a 93bffab7a44bc518799a2a68711ad790.jpg
a mardi-gras-2016-fuse-magazine.jpg
a wifi-crack.png

Compressing the tape archive file with bzip2, which is an alternative to gzip, but both gzip and bzip2 are still very good.

deusexmachina:stuff jason$ bzip2 images.tar

The archive I created, contains images, and therefore, does not compress at all, but this is just an example.

I created another tape archive file containing 3 source code files. This was pretty small.

deusexmachina:code jason$ tar -cvf code.tar *.*
a intro.c
a my.c
a myprog.c
deusexmachina:code jason$ ls -hula
total 40
drwxr-xr-x   6 jason  staff   192B 15 Jan 21:31 .
drwx------+ 44 jason  staff   1.4K 15 Jan 21:31 ..
-rw-r--r--   1 jason  staff   5.5K 15 Jan 21:31 code.tar
-rw-r--r--   1 jason  staff   169B 15 Jan 21:31 intro.c
-rwxr-xr-x   1 jason  staff   1.6K 15 Jan 21:31 my.c
-rwxr-xr-x   1 jason  staff   204B 15 Jan 21:31 myprog.c

But after compressing with bzip2, it is even smaller.

deusexmachina:code jason$ ls -hula
total 32
drwxr-xr-x   6 jason  staff   192B 15 Jan 21:34 .
drwx------+ 44 jason  staff   1.4K 15 Jan 21:31 ..
-rw-r--r--   1 jason  staff   1.2K 15 Jan 21:31 code.tar.bz2
-rw-r--r--   1 jason  staff   169B 15 Jan 21:31 intro.c
-rwxr-xr-x   1 jason  staff   1.6K 15 Jan 21:31 my.c
-rwxr-xr-x   1 jason  staff   204B 15 Jan 21:31 myprog.c

This proves that the good old Linux utilities are still very good at creating an archive and compressing them into a nice file.

Use this simple command to extract the files that have been packed into the tar.bz2 file.

deusexmachina:code jason$ tar -jxvf code.tar.bz2 
x intro.c
x my.c
x myprog.c

If the user creates a new folder and then wants to put the extracted files there instead, use this command line.

deusexmachina:code jason$ tar -jxvf code.tar.bz2 -C codefiles/
x intro.c
x my.c
x myprog.c

This will extract the files to the folder named “codefiles”.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.