Skip to Content
Watching Linux Evolve
Here you can learn how to use the rar and unrar programs from the Linux command line. You can learn how to install this tool, and how to extract rar archives.
Rar And Unrar
Rar is used to archive packages, while Unrar is used to extract existing archives. Thankfully the options for both tools are quite similar.
Next lets look at how you can install these popular tools from the Linux command line, these commands will work on any Ubuntu based system.
Installing Rar
First install Rar with the command below.
$ sudo apt-get install rar
Installing UnRar
Next you can install unrar with the following command.
$ sudo apt-get install unrar
When using the rar program there are several commands that can be chosen from for different functions. Just insert the command you need to specify the rar operation you desire. Here are a few basic rar commands.
Standard Syntax
This is the common usage for the rar tool. Use this command to archive files in the normal fashion. We will explain how to use unrar at the bottom of this section.
$ rar command -switch archive.rar files.txt
Add File To Rar Archive
With the command below you can add a files to an archive.
$ rar a archive.rar files.jpg
Add Comment To Archive
Use the command below to add a comment to your Rar archive, this is simply a short description to help you identify your archive.
$ rar c archive.rar comment
Delete Files From Archive
You can delete files from an existing Rar archive with the command specified below.
$ rar d archive.rar files.txt
Extract Files
This will extract all files in the specified archive to your current directory, no sub folders will be created.
$ rar e archive.rar files.txt
Extract With Sub-Directories
Extract files with full path included, sub-directories will be created.
$ rar x archive.rar
Refresh Files
Freshen the files in your archive with this command. This will update files changes since they were added to the archive. It will not add new files to your archive.
$ rar f archive.rar
Repair Archive
Repair a damaged archive with the command seen below.
$ rar r archive.rar
Reconstruct Missing Volumes
With the next command you can reconstruct missing volumes, useful for multi-volume rar archives.
$ rar rc archive.rar
Data Recovery Record
Add a data recovery record to your archive.
$ rar rr[N] archive.rar
Create Recovery Volume
Create recovery volumes that can later be used to rebuild damaged or missing files. This will create a .rev file usable for missing multi-volume archives.
$ rar rv[N] archive.rar
Test Archive
With the following command you may test your archive.
$ rar t archive.rar
Update Archive
Update your archive. This will add new files and update changes made since the archive was created.
$ rar u archive.rar files.txt
List Archive Contents
List the content of your archive with the command below.
$ rar l[t] archive.rar
List Archive Contents Verbosely
With the next command you can verbosely list archive contents. Same as above.
$ rar v[t] archive.rar
Rar switches can be used alongside commands, however every switch must be seperated by a space. Here are a few of the typical switches used with the rar program.
Sync Archive
Synchronize archive contents. When this switch is used the files not present in the update list will be deleted from the archive so use with caution.
-as
Lowercase File Names
Convert file names to lower case.
-cl
Uppercase File Names
Convert file names to upper case.
-cu
Delete Original Files
Delete files after archiving.
-df
No File Sorting
Do not sort files while adding to a solid archive.
-ds
No Empty Directories
Do not add empty directories.
-ed
Fresjem Files
Freshen files, this may be used for extracting or creating new archives.
-f
Encrypted Archive
File data and headers will be encrypted. The password IS case sensitive and entering a password is mandatory.
-hp PASSWORD
Set Compression Level
Set the compression level of your archive. By default -m3 is used by rar. Use any numbers in the following range to sacrifice speed or compression at the benefit of the other as you wish.
-m0, -m5
Overwrite Files
Use the following option to overwrite existing files.
-o+
No Overwriting
Do not overwrite existing files.
-o-
Add Archive Password
Encrypt files with the case sensitive password you choose.
-p PASSWORD
No Password
Do not ask for password.
-p-
Recursive Sub-directories
The following option will use recursive sub-directories.
-r
Data Recovery Record
Use the following options to add a data recovery record.
-rr[N]
Create recovery volume
The next option can be used to make a recovery volume.
-rv[N]
Test Archive
If you want to test files after archiving you can with this option.
-t
Update Files
I believe this will simply update the files in your archive to the newer versions.
-u
Create Multi-Volume Archive
Creates multiple volumes of the size you specify. Useful for multi-volume archives only.
-v SIZE
Here are a few basic commands you can use with the unrar program.
Standard Syntax
This is the common usage for the unrar command, additional commands and switches follow as shown below.
$ unrar command -switch archive.rar files.jpg /path/to/files
Extract Files
Extract files to the current working directory.
e
List Archive Contents
Use this to list the contents of an archive.
l
Test Archive
Test the integrity of archived files.
t
Verbose Archive List
Verbosely list the contents of an archive.
v
Use Full Paths
Extract files with full paths.
x
All switches must be seperated by a space and have dashes before them.
No Comments
The next options will turn off the display of comments.
-c-
Freshen Files
This option will Freshen files.
-f
Overwrite Files
You can overwrite existing files with this option.
-o+
No Overwrite Files
Do not overwrite existing files.
-o-
Extract With Password
Use a password to extract the archive.
-p PASSWORD
No Passwrd
Do not ask for password.
-p-
Create Sub-Directories
Creates recursive subdirectories while extracting.
-r
Update Files
Use the following shortcut to update all files.
-u
List All Volumes
Use the option below to display all volumes relating to an archive.
-v
Exclude Files
Exclude the file you specify.
-x FILE
Tags: bash, command, line, rar, shell, unrar | Posted in Command Line