How to Extract RAR Files Using Unrar Command Line

This guide provides a straightforward tutorial on extracting .rar archives using the unrar command-line utility. You will learn how to install the tool on various operating systems, execute basic and advanced extraction commands, extract archives to specific directories, handle password-protected files, and view archive contents without decompressing them.

Installing unrar

Before using the tool, ensure it is installed on your system:

  • Debian/Ubuntu: sudo apt update && sudo apt install unrar
  • Fedora/RHEL: sudo dnf install unrar
  • macOS (via Homebrew): brew install unrar

Basic Extraction Commands

The unrar tool primarily uses two commands to unpack files: x and e.

To extract files while preserving their original subfolders and paths, use the x switch:

unrar x filename.rar

Extract Without Directory Structure

To extract all files directly into your current working directory, ignoring any subdirectories stored inside the archive, use the e switch:

unrar e filename.rar

Extract to a Specific Directory

To unpack the contents into a destination folder other than the current directory, append the target path at the end of the command. Make sure to include a trailing slash:

unrar x filename.rar /path/to/destination/

If the destination directory does not exist, unrar will prompt to create it or create it automatically.

Extracting Password-Protected Archives

If the RAR archive is encrypted with a password, use the -p flag:

unrar x -pYourPassword filename.rar

Alternatively, you can run the command with just -p, and unrar will securely prompt you to type the password without displaying it on the screen:

unrar x -p filename.rar

Extracting Multi-Part RAR Archives

Multi-part archives are split into parts such as .part1.rar, .part2.rar, or .r00, .r01. To extract these, run the extract command exclusively on the first file in the sequence:

unrar x filename.part1.rar

The utility automatically detects and processes all subsequent volumes.

Viewing Archive Contents Without Extracting

To inspect the contents, file sizes, and dates inside a RAR archive without unpacking it, use the l (list) or v (verbose list) command:

unrar l filename.rar