Extract Only Directory Structure with Unrar

This article explains whether the unrar command-line utility can extract only an archive's directory tree without unpacking the files inside. While unrar does not feature a single, dedicated flag specifically for "directories only," you can achieve this outcome using exclusion masks or by parsing archive listings with standard command-line tools.

The Direct Answer

The standard unrar tool does not have a native, built-in switch that instructs it to extract solely directory records while ignoring every file. However, because RAR archives store directory paths as distinct records, you can recreate the full folder hierarchy without extracting actual file payloads using two primary methods.

Method 1: Using the File Exclusion Switch

You can tell unrar to extract with full paths (x) while excluding files using a wildcard filter.

unrar x -x*.* archive.rar /destination/path/
  • x: Extracts files with full paths.
  • -x*.*: Excludes any item containing a dot (.), which catches standard files with extensions while allowing directory entries to be created.

Caveat: Any files inside the archive that do not have a file extension (such as README or Linux binaries) will still be extracted.

Method 2: Listing Paths and Creating Directories (Linux / macOS)

The most reliable approach to avoid extracting any files—even those without extensions—is to list the contents using unrar and pass the directory paths directly to mkdir.

Run the following command in a terminal:

unrar lb archive.rar | grep '/$' | xargs -I {} mkdir -p "{}"

Alternatively, if directory entries are not suffixed with a slash in the bare list (lb), you can extract directory paths from file paths using dirname:

unrar lb archive.rar | while read -r line; do mkdir -p "$(dirname "$line")"; done

This reads every path in the archive, determines its parent directory, and creates the exact folder tree locally without decompressing any file contents.

Method 3: Windows PowerShell Alternative

If you are using Windows, you can achieve the same clean directory generation without extracting files by leveraging PowerShell:

unrar lb archive.rar | ForEach-Object {
    $dir = Split-Path $_ -Parent
    if ($dir -and -not (Test-Path $dir)) {
        New-Item -ItemType Directory -Path $dir -Force | Out-Null
    }
}

This reads the archive list, isolates each directory path, and creates the folder structure on your local drive.