Unrar Command to List Only Filenames
When managing RAR archives on the command line, you often need to
view the contents of an archive without uncompressing it or parsing
through verbose metadata like file sizes, ratios, and permissions. This
guide explains the specific command switch used in the
unrar utility to display a clean, bare list of filenames,
making it easy to inspect archives or pipe the output into other
command-line tools.
The Command: unrar lb
To print only the bare list of filenames and paths inside a RAR
archive, use the lb command.
unrar lb archive.rarHow It Works
unrar: Invokes the RAR extraction and inspection utility.lb: Stands for "List Bare." It strips away header banners, column titles, file dates, sizes, attributes, and summary footers, leaving only the file paths.archive.rar: The path to your target RAR file.
unrar lb vs. Standard
unrar l
The standard listing command, unrar l archive.rar,
outputs a formatted table containing detailed file information:
UNRAR 6.x freeware Copyright (c) 1993-2023 Alexander Roshal
Archive: archive.rar
Details: RAR 5
Attributes Size Date Time Name
----------- --------- ---------- ----- ----
-rw-r--r-- 1024 2023-10-12 14:00 document.pdf
-rw-r--r-- 2048 2023-10-12 14:01 image.png
----------- --------- ---------- ----- ----
3072 2
In contrast, running unrar lb archive.rar produces only
the file paths, one per line:
document.pdf
image.png
Common Use Cases
Exporting the File List to a Text File
You can redirect the bare output directly to a file to create a catalog or inventory:
unrar lb archive.rar > files.txtSearching for a Specific File
Because the output contains no extra text, you can pipe it to
grep to quickly check for the existence of a file:
unrar lb archive.rar | grep "target_file.txt"Using Inside Scripts and Loops
The clean output allows you to iterate over the contents within Bash
scripts without needing awk, cut, or regex
cleanup:
for file in $(unrar lb archive.rar); do
echo "Found: $file"
done