How to Test Archive Integrity Using Unrar
This guide explains how to test and verify the integrity of RAR
archive files using the unrar command-line utility. Testing
an archive allows you to detect file corruption, broken blocks, or
cyclic redundancy check (CRC) errors without needing to unpack the
contents to your disk.
The Basic Test Command
To check an archive's integrity, open your terminal and use the
t (test) command switch followed by the archive name:
unrar t archive.rarThe t switch instructs unrar to simulate
unpacking the files into memory and compute their checksums. If the
files are intact, the command will process each file and output an
All OK message upon completion. If any file is damaged,
unrar will display a CRC failed or
Corrupt file error pointing to the specific file.
Testing Multi-Part Archives
If your data is split across multiple volumes (e.g.,
archive.part1.rar, archive.part2.rar), you
only need to run the test command on the first volume:
unrar t archive.part1.rarunrar will automatically locate and sequentially test
the integrity of all subsequent volumes in the directory.
Testing Password-Protected Archives
For encrypted archives, you must provide the decryption key to verify the contents:
unrar t -p archive.rarThe -p flag prompts you to enter the password securely
without exposing it in your shell history. Alternatively, you can pass
the password directly:
unrar t -pYourPassword archive.rarNote: Ensure there is no space between -p and the
password string.
Checking Integrity via Exit Codes in Scripts
When automating archive checks via shell scripts, you can evaluate
the exit status of the command using $?:
unrar t -inul archive.rar
if [ $? -eq 0 ]; then
echo "Archive is intact."
else
echo "Archive is corrupted."
fiThe -inul switch disables standard output messages,
leaving only critical error messages, making it ideal for automated
scripts. An exit code of 0 denotes success, while any
non-zero value indicates a problem such as a CRC failure, missing
volume, or wrong password.