Home » How To » How to Use 7-Zip in Linux

How to Use 7-Zip in Linux

In this tutorial, we will see How to Use 7-Zip in Ubuntu and on Other Linux Distributions?

7-Zip is a free open source, cross-platform, powerful, and fully-featured file archiver with a high compression ratio, for Windows. It has a powerful command-line version that has been ported to Linux/POSIX systems. It has a high compression ratio in 7z format with LZMA and LZMA2 compression, supports many other archive formats such as XZ, BZIP2, GZIP, TAR, ZIP and WIM for both packing and unpacking; AR, RAR, MBR, EXT, NTFS, FAT, GPT, HFS, ISO, RPM, LZMA, UEFI, Z, and many others for extracting only. It provides strong AES-256 encryption in 7z and ZIP formats, offers a compression ratio that of 2-10 % for ZIP and GZIP formats (much better than those offered by PKZip and WinZip). It also comes with self-extracting capability for 7z format and it’s localized in up-to 87 languages.

The 7-Zip support is not enabled by default in most Linux distributions.

If you try to extract it, you may see this error:

Could not open this file type. There is no command installed for 7-zip archive files.

Don’t worry, you can easily install 7zip in Ubuntu or other Linux distributions. The one problem you’ll notice if you try to use the apt-get install command, you’ll see that there are no installation candidate that starts with 7zip. It’s because the 7Zip package in Linux is named p7zip., start with letter ‘p’ instead of the expected number ‘7’. Let’s see how to install 7zip in Ubuntu and (possibly) other Linux distributions.

How to Install 7zip in Linux

Install 7zip on Debian, Ubuntu or Linux Mint

Debian-based Linux distributions comes with three software packages related to 7zip and they are p7zipp7zip-full and p7zip-rar. It is suggested to install p7zip-full package, which supports many archive formats.

sudo apt-get install p7zip-full

Install 7zip on Fedora or CentOS/RHEL

Red Hat-based Linux distributions comes with two packages related to 7zip and they are p7zip and p7zip-plugins. It is suggested to install both packages.

To install these two packages, you need to enable EPEL repository on CentOS/RHEL distributions. On Fedora, no need to setup additional repository.

sudo yum install p7zip p7zip-plugins

Once the 7zip package installed, you can move further to learn some useful 7zip command examples to pack or unpack various types of archives in the following section.

The first thing you need is to install the p7zip package. You’ll find three 7zip packages in Ubuntu: p7zip, p7zip-full and p7zip-rar.

The difference between p7zip and p7zip-full is that p7zip is a lighter version providing support only for .7z while the full version provides support for more 7z compression algorithms (for audio files etc). The p7zip-rar package provides support for RAR files along with 7z. Installing p7zip-full should be sufficient in most cases but you may also install p7zip-rar for additional support for the rar file.

Use the following command to install 7zip support in Ubuntu and Debian-based distributions.

sudo apt install p7zip-full p7zip-rar

That’s good. Now you have 7zip archive support in your system.

7zip Command Examples in Linux

Create an Archive File

To create an .7z archive file, use "a" option. The supported archive formats for creation are 7z, XZ, GZIP, TAR, ZIP and BZIP2. If the given archive file exists already, it will “add” the files to an existing archive, instead of overwriting it.

7z a archive.7z uncompressed_files

To select an archive format, use -t (format name) option, which will allow you to select the archive format such as zip, gzip, bzip2, or tar (the default is 7z):

7z a -tzip archive.zip uncompressed_files

Extract Archive File in Linux

With 7Zip installed, you can either use the GUI or the command line to extract 7zip files in Linux.

In GUI, you can extract a .7z file as you extract any other compressed file. You right-click on the file and proceed to extract it.

In the terminal, you can extract a .7z archive file using this command:

7z e archive.7z

List All files of an Archive File

To see a list of files in an archive, use "l" (list) function, which will displays the type of archive format, method used, files in the archive among other information as shown.

7z l archive.7z

Test the Integrity of an Archive file

To test the integrity of an archive file, use "t" (test) function as shown.

7z t archive.7z

Set Compression Level

To set a compression level, use the -mx option as shown.

7z a -mx=9 -t7z archive.7z uncompressed_files

Update Existing Archive File

To update an existing archive file or remove the file(s) from an archive file, use "u" and "d" options, respectively.

7z u <archive-filename> <list-of-files-to-update>
7z d <archive-filename> <list-of-files-to-delete>

For Example:

7z u mytechmint.7z new_file.txt
7z d mytechmint.7z old_file.txt

Create Password Protected Archive File

To set a password to an archive file, use -p {password_here} flag as shown.

7z a -p<password_here> archive.7z uncompressed_files

For Example:

7z a -pPassW0rd mytechmint.7z mytechmint/

Other useful options available are as below:

  • a: Add files to archive
  • -p: Prompt for a password
  • -mx=9: Level of compression (9 being ultra)
  • -mhe: Encrypt file names
  • -t7z: Generate a 7z archive

Example:

7z a -p -mx=9 -mhe -t7z archive.7z www/ backup/

More options can be checked using “7z -h” or “7z –help“.

7z -h
7z --help

Leave a Comment