Extracting a Zero-Byte Archive with Unrar
When you attempt to extract a zero-byte file using the
unrar command-line utility, the process fails immediately
without altering your filesystem. This article explains how
unrar handles an empty file, the specific terminal errors
it generates, the exit codes returned to the operating system, and the
implications for automated scripts.
Archive Header Verification
Every valid RAR archive begins with a specific sequence of magic
bytes known as the file signature. For RAR 4.x archives, the signature
begins with the hex values 52 61 72 21 1A 07 00, while RAR
5.x archives start with 52 61 72 21 1A 07 01 00.
When unrar is executed, its first step is reading the
file header to determine the format, compression type, and file table.
Because a zero-byte file contains no data at all, unrar
cannot locate these mandatory identifier bytes.
Terminal Output and Error Behavior
If you run the extraction command on a zero-byte file:
unrar x empty.raror
unrar e empty.rarThe utility prints its standard header information and immediately returns an error indicating that the file is invalid:
UNRAR 6.x freeware Copyright (c) 1993-2024 Alexander Roshal
empty.rar is not RAR archive
No files to extract
Depending on the specific version of unrar or whether
the lightweight unrar-free implementation is used, the
error message may alternately state:
Corrupt archive or not a RAR file
Non-Zero Exit Code
When unrar fails to read a valid archive signature, it
terminates and returns a non-zero exit code to the shell. In the
official RAR utility, this typically returns exit code 2
(signifying a fatal error) or exit code 1 (a non-fatal
error or warning, depending on the environment).
You can observe this status code in a Linux or macOS shell immediately after running the command:
echo $?In shell scripts using set -e or automated pipelines
checking command success, this non-zero exit code will cause the
workflow to fail unless the error is explicitly caught and handled.
System and Filesystem Impact
The operation has zero footprint on your system:
- No extraction directories are created.
- No partial or empty payload files are written to the target location.
- System resources (CPU and memory) are freed instantly, as the program aborts at the initial read phase.