List Encrypted RAR Files with unrar Without Password
This guide explains how to inspect the contents of an encrypted RAR
archive using the command-line utility unrar without
encountering an interactive password prompt. By using the
-p- switch, you can instruct unrar to suppress
the password query entirely, allowing automated scripts or terminal
sessions to read file listings immediately when headers are not
encrypted, or fail gracefully when they are.
The Command
To list files inside an archive without being prompted for a password, run the following command:
unrar l -p- archive.rarTo view detailed archive attributes (such as permissions, compression
ratio, and date stamps), replace l with v:
unrar v -p- archive.rarTo output only the bare filenames without headers or footers:
unrar vb -p- archive.rarHow the -p- Switch
Works
By default, when unrar encounters an encrypted archive
or encrypted file entry, it halts execution and opens an interactive
prompt asking the user to input a password.
Adding -p- tells unrar not to query the
user for a password. It treats the password input as explicitly empty or
disabled, preventing the command from hanging in non-interactive
environments such as CI/CD pipelines, cron jobs, or automated bash
scripts.
Archive Types and Expected Behavior
The outcome of the command depends on how the RAR archive was originally encrypted:
1. Standard Encryption (Encrypted Data Only)
If the archive was created using standard encryption (the
-p flag during creation), only the contents of the files
are encrypted, while the central directory containing filenames and
metadata remains in plain text.
- Behavior:
unrar l -p- archive.rarwill successfully display the full list of files and metadata instantly without asking for a password.
2. Encrypted File Headers
If the archive was created with encrypted headers (the
-hp flag during creation), the filenames, file sizes, and
directory structures are completely encrypted alongside the file
data.
- Behavior: Because the file names physically cannot
be decrypted without the correct key,
unrarcannot list the contents. However, instead of halting the terminal to wait for user input,-p-causesunrarto exit immediately with an error indicating that the header is encrypted.
Automating and Suppressing Error Messages
If you are using this command in shell scripts to test whether an
archive's file list can be read without credentials, combine
-p- with the -inul switch to suppress standard
error output:
if unrar vb -inul -p- archive.rar > /dev/null 2>&1; then
echo "Archive list read successfully without a password."
else
echo "Archive headers are encrypted or file is invalid."
fi