Search Files in RAR Archive Without Extracting
This article explains how to inspect the contents of a RAR archive
using the unrar command-line tool to verify whether a
specific file exists without decompressing the archive. You will learn
the primary unrar listing commands, how to query specific
filenames or patterns directly, and how to pipe output to text-filtering
utilities like grep and findstr for automated
or case-insensitive searches.
Direct Search Using unrar
The quickest method to check for a file is passing the target
filename or wildcard pattern directly to the unrar l (list)
command.
Syntax
unrar l archive.rar "target_file.txt"If the file exists inside the archive, unrar will
display its details (size, ratio, date, and attributes). If the file
does not exist, the output table will show zero files.
Using Wildcards
You can use wildcards to search for partial names or specific file extensions:
unrar l archive.rar "*.pdf"Enclosing the pattern in quotes prevents your shell from attempting
to expand the wildcard against local files before passing it to
unrar.
Bare Listing for Scripting and Clean Output
By default, the l command prints headers, footers, and
metadata columns. To output only the raw file paths without surrounding
metadata, use the lb (list bare) command:
unrar lb archive.rar "target_file.txt"If the file is present, only its path will be printed. If it is
missing, unrar produces no output.
Piping Output to Search Tools
For case-insensitive matching or advanced regex filtering, pipe the bare list output to your operating system's standard search utilities.
On Linux and macOS (Using grep)
Use grep with the -i flag for
case-insensitive matching:
unrar lb archive.rar | grep -i "target_file"To quickly get a true/false status in a shell script, use the quiet
flag (-q):
if unrar lb archive.rar | grep -iq "target_file.txt"; then
echo "File found."
else
echo "File not found."
fiOn Windows (Using findstr)
In the Windows Command Prompt, use findstr with
/i for case-insensitive searches:
unrar lb archive.rar | findstr /i "target_file.txt"Searching Password-Protected Archives
If the file list itself is encrypted (created with the
-hp switch), unrar requires the archive
password to view the contents. Supply the password using the
-p switch:
unrar lb -pYourPassword archive.rar "target_file.txt"If only the files are encrypted but the file headers are not (created
with standard -p), you can list and search the filenames
using standard commands without providing a password.