Long explanation ahead to understand the issue before making the decision.
I was trying to recall how to open a random RAR file using p7zip command-line tool on Linux. After looking at some dated discussions on forum thread (lost citation due to private browsing), I managed to recall how I used p7zip to open RAR file last time. Problem solved, except for one misleading answer on Unix SE.
Earlier, I found this post on Unix SE: How to open rar file in linux? There are 9 answers posted under the question to this date, but most answers noted unrar
in different ways and only this answer mentioned about p7zip. Despite the answer had +5/-0 votes and one comment noted "it worked", the answer is actually misleading as follows.
sudo apt-get install p7zip 7zr x myfile.rar
On Windows I rely on 7zip for rar and every other archive file, and it works on Linux, too.
There are two apparent issues in the quoted answer.
First: The APT command to install p7zip
package on Debian/Ubuntu does not include the required package to successfully open a RAR file. p7zip
will suggest p7zip-full
, which will finally suggest the required package p7zip-rar
. Then again, suggested packages will not be installed unless using --install-suggests
option.
The manual page 7z(1) has noted the requirement, as per added bold text:
7-Zip is a file archiver supporting 7z (that implements LZMA compression algorithm featuring very high compression ratio), LZMA2, XZ, ZIP, Zip64, CAB, RAR (if the non-free p7zip-rar package is installed), ARJ, GZIP, BZIP2, TAR, CPIO, RPM, ISO, most filesystem images and DEB formats. Compression ratio in the new 7z format is 30-50% better than ratio in ZIP format.
Second: The subsequent command 7zr
from p7zip
package does not work with a RAR file.
From the sibling manual page 7zr(1), as per added bold text:
7zr is a stand-alone executable. 7zr is a "light-version" of 7za(1). 7zr handles password-less archives in the 7z, LZMA2, and XZ formats only.
From p7zip on ArchWiki, the difference between 7z, 7za and 7zr binaries has been noted as well.
The package includes three binaries,
/usr/bin/7z
,/usr/bin/7za
, and/usr/bin/7zr
. Their manual pages explain the differences:
7z(1)
uses plugins to handle archives.7za(1)
is a stand-alone executable that handles fewer archive formats than 7z.7zr(1)
is a stand-alone executable. It is a "light-version" of 7za that only handles 7z archives. In contrast to 7za, it cannot handle encrypted archives.
Therefore, the only command that works with RAR files is 7z
and neither of other two. That is indeed true and I have tested by myself. But that is not all and there is a third, hidden issue.
Hidden issue: RAR format has version compatibility issue, in which the RAR tool version and the RAR file version must be matching or supported. For example, if the RAR file was created by a newer RAR tool version 5, then the created RAR file can not be opened by the older RAR tool version 3. This issue can be reproduced with the newer and older versions of p7zip similarly.
Based on the long explanation above, I thought of writing a new answer that will explain to install the correct package, to use the correct command, and to use the correct version and perhaps with actual command output as proof. That seems easier to do without having to worry whether the suggested edit is appropriate or not, since that will result in much different answer from the original.
Then again, there are already 9 answers posted under the question and a new answer will increase that to a two-digit number. That may give a false impression that there are too many similar answers and I may be seen adding more noise under the question.
Finally, here is my meta question:
Should I write a new answer for p7zip to open RAR file, or should I just downvote the answer and leave a comment so that more experienced user can do something about it?
P.S.: By the time I finish put information in order and wrote this meta question, it was late hour and lately I am lacking sleep. I will follow up this again after few days or so.