How to Make Unrar Ignore System Umask Settings

Extracting RAR archives on Unix and Linux environments often requires strict control over resulting file permissions. This guide explains how the unrar utility interacts with system umask settings and details the specific commands required to prevent umask restrictions from modifying extracted files.

Default Behavior of UnRAR

The command-line unrar utility does not have a dedicated --ignore-umask command-line switch because native Unix unrar ignores the system umask by default. When you run standard extraction commands, unrar restores the exact POSIX file attributes and permission bits stored within the archive headers.

The switch that forces unrar to follow the system's umask is -ai (ignore file attributes). Therefore, simply omitting the -ai flag ensures unrar applies the archived permissions rather than applying the system mask:

unrar x archive.rar

Command to Override the Shell Umask

If your environment or shell configuration enforces a restrictive umask that interferes with archive creation or extraction processes, you can override the umask at execution time by invoking a subshell with a 000 mask:

(umask 000 && unrar x archive.rar)

Running this command executes the extraction in an isolated subshell where no permission bits are masked, leaving your main shell's umask unchanged.

Preserving Ownership and Full Permissions

To ensure that both permission bits and original owner/group IDs stored in the archive are completely restored without modification, combine the extraction command with the -ow switch and run it with superuser privileges:

sudo unrar x -ow archive.rar

The -ow flag instructs unrar to extract and apply the stored user and group information alongside standard file permissions.