How Unrar Handles Read-Only Destination Errors

When extracting RAR archives using the unrar command-line utility, attempting to write to a read-only destination directory causes the tool to fail immediately with a permission error. This article outlines the exact behavior of unrar under these conditions, including console output, process halting, exit codes, and how to resolve the issue.

Immediate Console Output

Because unrar requires write permissions to create new files or subdirectories, a read-only destination prevents the necessary system calls (such as mkdir or open) from succeeding. Upon encountering this restriction, unrar displays an explicit error message on the terminal:

Cannot create filename.ext
Permission denied

If the archive contains nested folders that need to be generated within the read-only directory, the error indicates a directory creation failure instead:

Cannot create directory /path/to/folder
Permission denied

Extraction Halting and Interactive Prompts

By default, in interactive mode, unrar may prompt the user asking whether to retry the operation, skip the file, or abort extraction. If the utility is running in non-interactive mode (such as via automated scripts using the -y or -id switches), it will fail to extract the affected file and continue to the next item or abort entirely, depending on whether subfolder creation is required. Any file that cannot be written is left unextracted; unrar will not attempt to bypass system permissions or redirect output automatically.

Return Codes and Exit Status

When a read-only directory prevents file creation, unrar terminates with a non-zero exit code. In standard implementations:

  • Exit Code 9 (Create file error): Indicates that unrar was completely unable to create the target file or directory due to filesystem permission restrictions or a write-protected medium.
  • Exit Code 1 (Non fatal error): May be returned in instances where some files were extracted elsewhere but specific read-only targets were skipped.

Scripts monitoring extraction tasks should check for Exit Code 9 to detect permission issues automatically.

Resolving the Error

To allow unrar to proceed, you must grant write permissions to the user executing the command:

  1. Modify Permissions: Use chmod on Unix-like systems to add write access (e.g., chmod u+w /path/to/destination).
  2. Change Ownership: If the directory belongs to another user, update ownership using chown (e.g., chown $USER /path/to/destination).
  3. Change Destination: Alternatively, specify a different, writable target path at the command line: unrar x archive.rar /path/to/writable/dir/.