Unrar to a Specific Directory in Linux

This guide explains how to extract RAR archives into a specific destination directory using the command-line tool unrar. You will learn the exact command syntax required to extract files while preserving the original folder structure, how to extract all files into a single flat directory, and how to handle common options such as passwords and overwriting existing files.

The Standard Extraction Command

To extract a RAR file into a designated target directory while preserving its internal folder structure, use the x switch followed by the archive name and the target path:

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

Always include the trailing slash (/) at the end of the destination path. If the destination directory does not exist, unrar will automatically create it.

Extracting Files Without Subdirectories

If you want to extract all files directly into the destination folder without preserving the subfolders stored inside the archive, replace x with the e switch:

unrar e archive.rar /path/to/destination/

This extracts all files into the specified directory as a single flat list, which can lead to overwritten files if multiple subfolders contain items with identical names.

Handling Paths with Spaces

If your archive name or destination directory contains spaces, wrap the paths in quotation marks:

unrar x "my archive.rar" "/home/user/My Documents/"

Useful Additional Options

You can combine destination commands with other common flags:

  • Password-protected archives: Add -p followed by the password to extract without being prompted interactively:
    unrar x -pSecretPassword archive.rar /path/to/destination/
  • Overwrite existing files automatically: Use -o+ to force overwrite:
    unrar x -o+ archive.rar /path/to/destination/
  • Skip existing files: Use -o- to skip files that already exist in the target directory:
    unrar x -o- archive.rar /path/to/destination/