We receive a 7z file and we want to extract it on the command line. We search on Google and we are confused because some examples use 7z and some others use 7za.
We can use both 7z or 7za or even 7zr as long as the format for the archive is 7z.
From Arch Linux Wiki:
7z uses plugins to handle archives.
7za is a stand-alone executable. 7za handles fewer archive formats than 7z, but does not need any others.
7zr is a stand-alone executable. 7zr handles fewer archive formats than 7z, but does not need any others. 7zr is a “light-version” of 7za that only handles 7z archives.
Create an archive of the current directory:
7z a filename.7z
Create an archive of a specific directory:
7z a filename.7z /path-to-dir
Extract a 7z archive in the current directory with full path:
7z x filename.7z
Extract a 7z archive in the current directory without directory names:
7z e filename.7z
You should not have a “-” before a or x. It will not work, a will “Add files to archive” and x will extract an archive with full path.
If you have 7za binary, you can use it as well. In CentOS 7, 7z binary is available only after installing p7zip-plugins.
rpm -qf `which 7za`
rpm -qf `which 7z`
Whereas in Mac, brew install p7zip installs 7z, 7za and 7zr.
This will create a 7-zip archive of the current directory protected by a password
7z a filename.7z -pPASSWORD
where a stands “Add files to archive” and PASSWORD is the password. To archive a different directory use:
7z a filename.7z -pPASSWORD /path/dir
To extract this file
7z x filename.7z -pPASSWORD
where x stands for extract. You can use 7za where 7z binary is not available.
7za e filename.7z
If you don’t have 7za installed, the package to install is p7zip in Centos/RHEL.
$ rpm -qf `which 7za`