How to Unrar with a Password List
This guide explains how to extract a password-protected RAR archive
using a text file containing a list of potential passwords. Because the
standard unrar utility does not natively support reading a
list of passwords from a file, this process is accomplished using a
lightweight command-line script in Linux/macOS (Bash) or Windows
(Batch/PowerShell) to test each password until the archive extracts
successfully.
Understanding the Approach
The standard syntax to extract an archive with a specific password
using unrar is:
unrar x -pYourPassword archive.rarTo test multiple passwords from a file (e.g.,
passwords.txt), a loop reads the file line by line, passes
each entry to unrar using the test command
(unrar t), and performs the actual extraction
(unrar x) once a valid password is found. Using the test
command first avoids partial or corrupted extractions from incorrect
attempts.
Method 1: Linux and macOS (Bash Script)
On Linux or macOS, you can run a Bash loop directly in your terminal.
- Place
archive.rarandpasswords.txtin the same directory. - Open your terminal and navigate to that directory.
- Run the following command:
while IFS= read -r pass; do
if unrar t -inul -p"$pass" archive.rar; then
echo "Password found: $pass"
unrar x -p"$pass" archive.rar
break
fi
done < passwords.txtExplanation of flags:
t: Tests archive files without extracting them.-inul: Suppresses standard console output, keeping the terminal clean.-p"$pass": Passes the current password variable.x: Extracts files with full paths once the valid password is confirmed.break: Stops the loop as soon as extraction succeeds.
Method 2: Windows (PowerShell)
On modern Windows systems, PowerShell provides a reliable way to iterate through a password list.
- Open PowerShell and navigate to the folder containing your archive and password list.
- Ensure
unrar.exeis available in your system PATH (or use the full path toWinRAR.exe). - Run the following script:
$passwords = Get-Content .\passwords.txt
foreach ($pass in $passwords) {
& unrar t -inul -p"$pass" .\archive.rar
if ($LASTEXITCODE -eq 0) {
Write-Host "Password found: $pass"
& unrar x -p"$pass" .\archive.rar
break
}
}Method 3: Windows Command Prompt (Batch)
If you prefer using the traditional Windows Command Prompt
(cmd.exe):
- Create a file named
extract.batin the same folder asarchive.rarandpasswords.txt. - Insert the following code:
@echo off
for /f "usebackq delims=" %%P in ("passwords.txt") do (
unrar t -inul -p"%%P" archive.rar >nul 2>&1
if not errorlevel 1 (
echo Password found: %%P
unrar x -p"%%P" archive.rar
goto :found
)
)
echo No valid password found in list.
:found- Run
extract.batfrom the command line.