How to Keep Broken Files in Unrar
This article explains how to handle corrupted or incomplete archives
using the unrar command-line utility. It details the
specific switch used to prevent unrar from deleting damaged
files upon encountering extraction errors, clarifies command-line
limitations regarding automatic file renaming, and outlines how to
handle broken files effectively.
The Keep Broken Files Switch
(-kb)
The switch that instructs unrar to retain damaged or
incomplete files is -kb (Keep Broken).
By default, when unrar encounters a CRC error, missing
volume, or data corruption during extraction, it aborts the process for
that file and deletes the partial output from your disk. Applying the
-kb switch overrides this behavior, forcing the utility to
leave whatever portion of the file was successfully decompressed in the
destination directory.
Basic Command Syntax
To extract an archive and keep any damaged files, use:
unrar x -kb archive.rarx: Extracts files with full paths.-kb: Retains broken or corrupted extracted files.
Can Unrar Automatically Rename Broken Files?
Standard unrar (both the freeware command-line version
and the RAR command line by RARLAB) does not include a
switch to automatically rename broken files or append a custom file
extension (such as .broken or .corrupt).
When -kb is enabled:
unrarwrites the file using its standard filename defined in the archive header.- If a CRC or extraction error occurs, a warning is printed to the console.
- The incomplete file remains on disk under its original filename without modification.
How to Rename Broken Files
Because unrar lacks native extension-modifying switches
for damaged files, post-processing via a shell script or batch file is
required if you need to flag broken outputs.
unrar outputs non-zero exit codes when errors occur
(exit code 3 denotes a CRC error, while 1
indicates a non-fatal error). You can monitor extraction logs or
standard error to identify damaged files and rename them
programmatically.
Bash Example (Linux/macOS)
unrar x -kb archive.rar | tee extraction.log
# Search the log for CRC errors and rename affected files
grep "CRC failed" extraction.log | awk '{print $NF}' | while read -r filename; do
if [ -f "$filename" ]; then
mv "$filename" "$filename.corrupt"
fi
doneThis approach allows you to retain partially recovered data while explicitly marking damaged items with your desired extension.