Clear File Attributes After Unrar Extraction

When extracting RAR archives, files frequently retain restricted permissions, hidden flags, or read-only statuses embedded by the original creator. This guide explains how to prevent unrar from applying archived file attributes during the extraction process, as well as how to recursively reset file attributes immediately after extraction on both Windows and Linux systems.

Prevent Attributes During Extraction with Unrar

The cleanest way to handle file attributes is to instruct unrar to ignore them entirely during extraction. By default, unrar attempts to restore original file properties such as Read-Only, System, Hidden, and Archive flags.

You can bypass this behavior using the -ai switch:

unrar x -ai archive.rar
  • x: Extracts files with full paths.
  • -ai: Ignore file attributes. The extracted files will inherit the default permissions and attributes of the destination directory instead of the attributes saved in the archive.

Clear Attributes After Extraction on Windows

If files have already been extracted with unwanted attributes (such as Read-Only or Hidden), you can clear them using the native Windows Command Prompt tool attrib.

Open Command Prompt, navigate to the target folder, and run:

attrib -r -a -s -h *.* /s /d

Parameter Breakdown:

  • -r: Clears the Read-Only attribute.
  • -a: Clears the Archive attribute.
  • -s: Clears the System attribute.
  • -h: Clears the Hidden attribute.
  • /s: Applies the command to matching files in the current folder and all subfolders.
  • /d: Applies the command to directories as well as files.

Reset Attributes and Permissions on Linux

On Linux and Unix-like environments, unrar may restore strict POSIX permissions or extended file attributes.

1. Reset Standard POSIX Permissions

To strip restricted read-only permissions and set safe defaults across all extracted files and folders, run:

# Set directories to standard read, write, and execute permissions
find /path/to/extracted/ -type d -exec chmod 755 {} +

# Set files to standard read and write permissions
find /path/to/extracted/ -type f -exec chmod 644 {} +

2. Remove Extended Attributes (xattr)

If the archive restored extended attributes or security metadata, you can clear them using attr:

# On Linux (removes user-defined attributes recursively)
setfattr -h -x user.* /path/to/extracted/*

# On macOS (clears all extended attributes recursively)
xattr -rc /path/to/extracted/