How Unrar Handles Existing Directory Permissions

When extracting an archive using unrar, handling pre-existing directories with differing permissions is governed by strict preservation and security defaults. This article explains how the utility treats existing folder attributes, why permission conflicts occur, the role of overwrite switches, and how to force or prevent permission updates during extraction.

Default Extraction Behavior

By default, unrar does not modify the permissions of directories that already exist on the target file system. When you run an extraction command such as unrar x archive.rar, the utility performs the following checks for directories:

  1. Detection: It checks if the destination directory path already exists.
  2. Bypass: If the directory is present, unrar simply traverses into it to extract the contained files. It skips applying the archived directory permissions, leaving the target directory's existing chmod mode, ownership, and Access Control Lists (ACLs) untouched.
  3. Creation: Permissions and attributes stored inside the RAR archive are applied solely to directories that unrar creates from scratch during the extraction process.

The Role of Overwrite Switches

Standard overwrite flags do not alter how unrar treats existing directory metadata:

  • -o+ (Overwrite all): Forces unrar to overwrite existing files without prompting. It does not force an update to the permissions or ownership of pre-existing directories.
  • -o- (Skip existing files): Skips existing files entirely and similarly leaves existing directory metadata unchanged.

Because RAR formats treat directory records differently from file data, overwrite commands apply almost exclusively to file content rather than updating the metadata of parent or existing directory structures.

Influence of User Privileges and Umask

How permissions are assigned—and whether they can be modified—also depends on the execution context:

  • Standard User: A standard user lacks the privilege to alter permissions on directories they do not own. Even if unrar attempted to update the directory mode to match the archive, the operating system would deny the action unless the user owns the directory.
  • Root / Superuser: Running unrar as root allows the tool to set user/group ownership (chown) and exact permissions (chmod) on newly created directories. However, pre-existing folders will still retain their original permissions unless explicitly removed prior to extraction.
  • File Creation Mask (umask): When new directories are created, the resulting permissions are typically filtered through the user's active umask unless the archive was created with explicit POSIX attribute preservation.

How to Apply Archived Permissions to Existing Directories

If you need the directory structure to precisely mirror the permissions stored inside the archive, unrar does not provide an in-place directory metadata update switch. You must use one of the following approaches:

  1. Remove the Existing Directories: Delete or rename the conflicting directory tree before extracting. This forces unrar to recreate the folders and apply the stored attributes directly.
  2. Extract to a Temporary Location: Extract the archive into an empty temporary folder, verify the desired directory permissions, and use tools like rsync with the --perms and --owner flags to synchronize the attributes onto the destination directory.