Unrar Command to List Files Sorted by Size
The unrar utility does not include a native flag to sort
archive contents by file size, but you can achieve this by piping the
listing output into the Linux sort command. This guide
explains how to view the files inside a RAR archive ordered by size,
whether you need them listed from smallest to largest or largest to
smallest.
The Command to List Files by Size
To list all files in a RAR archive sorted numerically by size (largest to smallest), use the following command:
unrar l archive.rar | sort -k 2,2 -n -rFor ascending order (smallest to largest), omit the -r
flag:
unrar l archive.rar | sort -k 2,2 -nReplace archive.rar with the actual path to your RAR
file.
How It Works
unrar l archive.rar: Thel(list) command outputs standard details about the files within the archive, arranged in columns: Attributes, Size, Date, Time, and Name. The file size is located in the second column.|(Pipe): Redirects the standard text output of theunrarcommand directly into thesortprogram.-k 2,2: Instructssortto evaluate only the second column (the file size) as the sort key.-n: Specifies a numeric sort, ensuring that numbers are sorted by value rather than alphabetical order.-r: Reverses the sorting order so that the largest files appear first at the top of the output.
Clean Output Showing Only Size and Filename
If you want to strip out header lines, dates, and attributes to view
only the size and filename sorted by size, you can filter the output
using awk:
unrar l archive.rar | awk '$2 ~ /^[0-9]+$/ {print $2, $5}' | sort -n -rThis filter ensures only lines with a valid numeric size are processed, producing a clean two-column output displaying the size in bytes alongside the filename.