We usually associate RAR files with Windows, however more and more people use Ubuntu which makes it necessary to know how to compress and decompress RAR files in Ubuntu.
In case you didn't know, RAR stands for Roshal Archive and is a proprietary format with a lossless compression algorithm. Although RAR is slower than ZIP, it has a higher compression rate and better data redundancy.
How to compress files into rar?
Due to licensing issues, an Ubuntu installation does not include packages for RAR files natively.
Open a terminal and install a rar package:
sudo apt install rar
Here is a basic syntax to compress files:
rar [command] [ArchiveName] [file]
sudo rar a rartest file1.txt file2.txt
To add a password to your archive, just add
-p option to the end of your command and you will be prompted to enter a password:
sudo rar a rartest file1.txt file2.txt -p
Decompress RAR files on Ubuntu
We have to install a package called unrar from the official Ubuntu repositories.
Run the following in your terminal:
sudo apt install unrar
Follow this syntax to decompress files in Ubuntu:
unrar x [rar-file]
If the file is password-protected, you will be prompted immediately.
Congratulations! You have learned how to compress and decompress files from a terminal in your Ubuntu Shell.
Please sign in to leave a comment.