Rar is very popular compression format used for different purposes. A lot of files like documents, image files, source code etc. are compressed using rar compression format. In this tutorial we will look how to install rar tool for Ubuntu, Debian, Kali and Mint and than list and extract files and directories.
We will use
apt package manager in order to install
$ apt install unrar
List Rar File Contents
We can list contents of a rar files with
l option and the rar file name. In this example we will list contents of rar file named
$ unrar l ans.rar
The list operation will print attributes, size, date time and names.
Unrar All Files and Directories
We can use
e option in order to extract all files and directories inside a rar file. In this example we will extract contents of
-r is used to extract recursively which means all sub files and directories will be extracted too.
$ unrar e -r ans.rar
Unrar Single File or Directory
Some times we may need to extract only single file or directory from a rar file. This may be a backup
rar file where we only need a single file or directory. We need to specify the file and directory path and name in relative manner. In this example we will extract file named
$ unrar e ans.rar data.txt
Or if the file is locate in the
back/files directory we can use following command.
$ unrar e ans.rar back/files/data.txt
Preserve Directory Structure
While taking backups with rar command the absolute directory path can be stored into the rar file. This is useful for recover process where we do not need to specify the extract path explicitly. We can use
x option inorder to preserve directory structure while extracting. We will use
-r as recursive extract.
$ unrar x -r ans.rar