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:
- Detection: It checks if the destination directory path already exists.
- Bypass: If the directory is present,
unrarsimply traverses into it to extract the contained files. It skips applying the archived directory permissions, leaving the target directory's existingchmodmode, ownership, and Access Control Lists (ACLs) untouched. - Creation: Permissions and attributes stored inside
the RAR archive are applied solely to directories that
unrarcreates 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): Forcesunrarto 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
unrarattempted 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
unraras 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 activeumaskunless 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:
- Remove the Existing Directories: Delete or rename
the conflicting directory tree before extracting. This forces
unrarto recreate the folders and apply the stored attributes directly. - Extract to a Temporary Location: Extract the
archive into an empty temporary folder, verify the desired directory
permissions, and use tools like
rsyncwith the--permsand--ownerflags to synchronize the attributes onto the destination directory.