#TIL : Compressing and Extracting files with rar in Linux


17 May 2017 / by KhanhIceTea

zip and tar disadvantages

All unicode filename will be transform to weird character, so it makes broken paths and broken links

Notice

rar and unrar in Linux isn't same version and so don't use unrar to extract archived file by rar (It causes invalid full paths)

Installation

Ubuntu :

$ sudo apt install rar

Redhat ( using RPMForge )

$ sudo yum install rar

Compressing files, folder

Compressing files

$ rar a result.rar file1 file2 file3 fileN

Compressing dir and its subdirs (remember with trailing slash in the end)

$ rar a -r result.rar folder1/

Locking RAR file with password (adding -p"THE_PASSWORD_YOU_WANT")

$ rar a -p"0cOP@55w0rD" result.rar file1 file2 file3 fileN
$ rar a -p"0cOP@55w0rD" -r result.rar folder1/

Extracting file

Listing content of RAR file

$ rar l result.rar

Extracting RAR file to current dir

$ rar e result.rar

Extracting RAR file to current dir with fullpath

$ rar x result.rar

WANT MORE ?

Asking it !

$ rar -?

BONUS

WHAT IF I TOLD U THAT A RAR FILE BIGGER 35 TIMES THAN ITS ORIGINAL FILE ?

$  echo 'a' > a.txt
$  rar a a.rar a.txt

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Evaluation copy. Please register.

Creating archive a.rar

Adding    a.txt                                                       OK 
Done
$  ls -al
total 72
-rw-r--r-- 1 root root    77 May 17 14:18 a.rar
-rw-r--r-- 1 root root     2 May 17 14:17 a.txt

bus rar


Sound good ?