Preserve File Owner and Group Ownership in Unrar
This article explains how to restore and preserve original user and
group ownership when extracting RAR archives using the command-line
utility unrar. By utilizing specific flags and appropriate
system permissions, you can ensure that files extracted on Unix-like
systems retain their original ownership metadata rather than defaulting
to the user running the extraction command.
The -ow Switch
To preserve or restore user and group ownership when extracting
files, use the -ow switch with unrar.
sudo unrar x -ow archive.rarx: Extracts files with full paths.-ow: Tellsunrarto restore file owner and group identities.
Prerequisites for Preserving Ownership
For ownership restoration to work successfully, two conditions must be met:
1. Elevated Privileges
On Linux and Unix-like operating systems, only the superuser
(root) has permission to assign file ownership to another
user. If you run unrar x -ow as a standard user, the
operation will fail to change the owner and will fall back to assigning
ownership to the current user. Always prepend the command with
sudo or execute it as root.
2. Archive Creation with Ownership Data
The unrar utility can only restore ownership if that
metadata was stored when the archive was initially created. Standard RAR
creation commands do not store user and group IDs by default.
To ensure ownership data is present in an archive, the archive must
be created using the -ow switch with the rar
utility:
rar a -ow archive.rar /path/to/filesIf an archive was created without the -ow flag, the
ownership data does not exist inside the archive, and unrar
will be unable to restore it.