RAR archives remain common for distributing software, backups, and multi-part downloads, so the ability to open them directly on Linux keeps workflows efficient and avoids switching tools or operating systems. Handling RAR files from the terminal also integrates well with scripts and remote administration over SSH.
The proprietary RAR format stores one or more files in a compressed container, and on Linux extraction is typically handled by the unrar utility. Once available, unrar can identify archive details, test integrity, and extract content with or without preserving the original directory structure.
Because unrar is not always installed by default and RAR archives can be large or untrusted, it is important to choose the correct package, check free disk space, and extract into a suitable directory. Archives from untrusted sources should be inspected carefully and, where appropriate, scanned with security tools before opening.
Steps to extract RAR files on Linux:
- Open a terminal on the Linux system.
- Confirm the file is a RAR archive using the file command.
$ file archive.rar archive.rar: RAR archive data, v5
- Install the unrar utility from the package repository if it is not already present.
$ sudo apt update && sudo apt install --assume-yes unrar # Ubuntu and Debian [sudo] password for user: ##### snipped ##### The following NEW packages will be installed: unrar 0 upgraded, 1 newly installed, 0 to remove, and 0 not upgraded. Need to get 113 kB of archives. After this operation, 400 kB of additional disk space will be used. ##### snipped #####
On CentOS 7 and similar Red Hat variants where unrar is not available, install unar as an alternative:
$ sudo yum install --assumeyes epel-release && sudo yum install --assumeyes unar # CentOS 7 and other Red Hat variants [sudo] password for user:
On openSUSE and other SUSE variants, install unrar from the main repositories:
$ sudo zypper refresh && sudo zypper --non-interactive install unrar # openSUSE and other SUSE variants [sudo] password for root: Repository 'Main Repository (NON-OSS)' is up to date. Repository 'Main Repository (OSS)' is up to date. Repository 'Main Update Repository' is up to date. All repositories have been refreshed. Loading repository data... Reading installed packages... Resolving package dependencies... The following NEW package is going to be installed: unrar 1 new package to install. Overall download size: 155.3 KiB. Already cached: 0 B. After the operation, additional 334.1 KiB will be used. Continue? [y/n/v/...? shows all options] (y): y
- Preview the contents of the RAR file before extraction.
$ unrar l archive.rar UNRAR 5.71 freeware Copyright (c) 1993-2019 Alexander Roshal Archive: archive.rar Details: RAR 5 Attributes Size Date Time Name ----------- --------- ---------- ----- ---- -rw-rw-r-- 0 2019-11-02 01:41 archive/folder-02/file-02 -rw-rw-r-- 0 2019-11-02 01:41 archive/folder-02/file-01 -rw-rw-r-- 0 2019-11-02 01:41 archive/folder-01/file-02 -rw-rw-r-- 0 2019-11-02 01:41 archive/folder-01/file-01 drwxrwxr-x 0 2019-11-02 01:41 archive/folder-02 drwxrwxr-x 0 2019-11-02 01:41 archive/folder-01 drwxrwxr-x 0 2019-11-02 01:41 archive ----------- --------- ---------- ----- ---- 0 7The l command lists archive contents without extracting any files.
- Check that sufficient free disk space is available at the extraction target.
$ df -h temp/ Filesystem Size Used Avail Use% Mounted on /dev/sda2 20G 4.3G 15G 23% /
Extracting large RAR archives without enough free space can leave partially written files and corrupt the target directory.
- Create a directory to hold the extracted files if a separate location is desired.
$ mkdir directory
- Change into the directory that will receive the extracted files.
$ cd directory
- Extract the files from the RAR archive while preserving the directory structure.
$ unrar x ~/file.rar UNRAR 5.71 freeware Copyright (c) 1993-2019 Alexander Roshal Extracting from /home/user/file.rar Creating folder OK Creating folder/sub-01 OK Extracting folder/sub-01/file-01 OK Extracting folder/sub-01/file-02 OK All OK
The x command extracts each entry with its full path as stored in the archive. Other useful unrar commands are available from the built-in help:
$ unrar UNRAR 5.71 freeware Copyright (c) 1993-2019 Alexander Roshal Usage: unrar <command> -<switch 1> -<switch N> <archive> <files...> <@listfiles...> <path_to_extract\> <Commands> e Extract files without archived paths l[t[a],b] List archive contents [technical[all], bare] p Print file to stdout t Test archive files v[t[a],b] Verbosely list archive contents [technical[all],bare] x Extract files with full path - Verify the extracted files and directory layout recursively.
$ ls -R .: folder ./folder: sub-01 ./folder/sub-01: file-01 file-02
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
