Unrar Default Behavior with Corrupted Files

When extracting archives, encountering data corruption is a common issue that can interrupt automated workflows or manual extractions. This article outlines the default behavior of the unrar command-line utility when it meets a damaged or corrupted file, explaining how it handles file cleanup, error output, and process exit codes, along with how to modify this behavior if needed.

Automatic Deletion of Corrupted Files

By default, unrar deletes any corrupted file it extracts. When you initiate an extraction using standard commands such as unrar x archive.rar or unrar e archive.rar, the utility writes the unpacked data to disk while simultaneously computing its Cyclic Redundancy Check (CRC) or checksum.

If the calculated checksum does not match the checksum stored in the archive header, unrar flags the file as damaged. To prevent users or applications from inadvertently using incomplete or broken data, the utility automatically removes the target file from the filesystem immediately after the error is detected.

Error Messages and Exit Codes

When corruption is detected, unrar alerts the user through standard error streams:

  • Console Output: The terminal displays a specific diagnostic message, usually reading: Checksum error in filename.ext. The file is corrupt.
  • Exit Status: The process terminates with a non-zero exit code. Specifically, unrar returns exit code 3 (Fatal error / CRC error), allowing automated scripts to detect that the extraction failed.

If an archive contains multiple files, unrar will continue attempting to extract the remaining valid files, but any individual file that fails the integrity check is deleted.

How to Override the Default Behavior

In scenarios where partial data recovery is useful—such as salvageable video streams or plain text—you can override this default deletion behavior by using the -kb (Keep Broken) switch:

unrar x -kb archive.rar

The -kb flag instructs unrar to retain corrupted or partially extracted files on disk instead of wiping them, while still logging the integrity error to the console.