Display unrar File Attributes in Octal Format
The official unrar command-line utility does not provide
a native flag to output file permissions directly in octal format (such
as 0755 or 0644). When inspecting archives,
unrar outputs POSIX file permissions strictly in symbolic
notation (such as -rwxr-xr-x). To display these attributes
in octal notation without extracting the files, you must use the
technical listing command in unrar and parse its symbolic
output using a shell pipeline or script.
Understanding unrar Permission Output
When listing archive contents with detailed attributes, run:
unrar lt archive.rarThe lt command instructs unrar to show
technical information. Within the output, permissions appear on the
Attributes line:
Attributes: -rwxr-xr-x
Name: script.sh
Because unrar does not include an option like
--octal, converting -rwxr-xr-x into
755 requires translating the standard 9-character
permission mask into numerical bits.
Method 1: Using an AWK Pipeline (Recommended)
You can pipe the output of unrar lt directly into
awk to calculate the octal values on the fly. This solution
works out of the box on standard Linux and macOS terminal environments
without writing files to disk.
Run the following command:
unrar lt archive.rar | awk '
/^[ \t]*Attributes:[ \t]*/ {
attr = $2
u = (substr(attr,2,1)=="r"?4:0) + (substr(attr,3,1)=="w"?2:0) + (substr(attr,4,1)=="x"?1:0)
g = (substr(attr,5,1)=="r"?4:0) + (substr(attr,6,1)=="w"?2:0) + (substr(attr,7,1)=="x"?1:0)
o = (substr(attr,8,1)=="r"?4:0) + (substr(attr,9,1)=="w"?2:0) + (substr(attr,10,1)=="x"?1:0)
mode = sprintf("%d%d%d", u, g, o)
}
/^[ \t]*Name:[ \t]*/ {
sub(/^[ \t]*Name:[ \t]*/, "")
print mode, $0
}'How It Works:
- Attribute Extraction: Matches the
Attributes:line and reads the 10-character string (e.g.,-rw-r--r--). - Bit Calculation: Evaluates User (
u), Group (g), and Other (o) triplets using standard binary weights (r=4,w=2,x=1). - Filename Association: Matches the subsequent
Name:line and prints the octal representation alongside the archive path.
Method 2: Using a Python One-Liner
If you prefer Python for handling multi-byte characters or complex archive paths, run:
unrar lt archive.rar | python3 -c '
import sys, re
mode = ""
for line in sys.stdin:
attr_match = re.search(r"Attributes:\s*([drwxstST-]{10})", line)
if attr_match:
p = attr_match.group(1)[1:]
val = 0
for char in p:
val = (val << 1) | (1 if char in "rwxst" else 0)
mode = oct(val)[2:].zfill(3)
name_match = re.search(r"Name:\s*(.*)", line)
if name_match and mode:
print(f"{mode} {name_match.group(1)}")
mode = ""
'Method 3: Parsing
unrar v -c- Table Format
If you prefer standard table listings rather than technical multi-line listings, use verbose list mode:
unrar v -c- archive.rarThis prints a tabular layout where the first column contains the permissions. You can filter and translate this output using:
unrar v -c- archive.rar | awk '
/^[d-]r/ {
attr = $1
u = (substr(attr,2,1)=="r"?4:0) + (substr(attr,3,1)=="w"?2:0) + (substr(attr,4,1)=="x"?1:0)
g = (substr(attr,5,1)=="r"?4:0) + (substr(attr,6,1)=="w"?2:0) + (substr(attr,7,1)=="x"?1:0)
o = (substr(attr,8,1)=="r"?4:0) + (substr(attr,9,1)=="w"?2:0) + (substr(attr,10,1)=="x"?1:0)
filename = $NF
printf "%d%d%d %s\n", u, g, o, filename
}'This produces clean, two-column output displaying the numerical octal mask alongside each target file.