How to Stop Unrar Creating a Root Folder

When extracting a RAR archive, the command-line utility unrar often extracts contents into an enclosing root directory, either because of the extraction command used or because the archive was packaged with an internal parent folder. This guide covers how to prevent unrar from generating an unwanted root directory, whether you want to flatten all files into a single location or preserve subdirectories while stripping the top-level folder.

Extracting Files Without Folders (Flatten Archive)

If you want to extract all files directly into your current directory or a specific folder without any subdirectories or root folders, use the e (extract) command instead of x (extract with full paths).

unrar e archive.rar

To extract directly into a target folder without creating subfolders:

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

The e switch instructs unrar to ignore the archive's internal path structures, dumping all files directly into the specified directory.


Preserving Subfolders While Removing the Top-Level Folder

The standard unrar tool does not have a native --strip-components flag like tar. If the archive contains a root folder that encloses other nested folders and you want to keep the nested structure without the root parent, use one of the following methods.

Option 1: Use bsdtar with Strip Components

If your system has bsdtar installed (standard on macOS and available on Linux via libarchive-tools), you can unpack the RAR file and remove the root directory level dynamically:

bsdtar --strip-components=1 -xf archive.rar

This removes the primary root folder and preserves any subfolders inside it.

Option 2: Extract, Move, and Clean Up via Shell

If you are strictly using unrar, extract the archive normally, move the contents out of the generated root folder, and delete the empty directory:

unrar x archive.rar
mv root_folder/* .
rmdir root_folder

Replace root_folder with the actual name of the top-level directory unpacked by the archive.