10 7zip (File Archive) Command Examples in Linux

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.

How to Install 7zip in Linux

The port of 7zip on Linux systems is called p7zip, this package comes pre-installed on many mainstream Linux distributions. You need to install the p7zip-full package to get the 7z, 7za, and 7zr CLI utilities on your system, as follows.

Install 7zip on Debian, Ubuntu or Linux Mint

Debian-based Linux distributions comes with three software packages related to 7zip and they are p7zip, p7zip-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.

Learn 7zip Command Examples in Linux

1. 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 hyper.7z hyper_1.4.2_i386.deb
Create 7z Archive File in Linux
Create 7z Archive File in Linux

2. To extract an .7z archive file, use "e" option, which will extract the archive in the present working directory.

$ 7z e hyper.7z
Extract 7z Archive File in Linux
Extract 7z Archive File in Linux

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

$ 7z a -tzip hyper.zip hyper_1.4.2_i386.deb
Create 7z Zip File in Linux
Create 7z Zip File in Linux

4. 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 hyper.7z
List 7z File Information
List 7z File Information

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

$ 7z t hyper.7z
Check 7z File Integrity
Check 7z File Integrity

6. To backup a directory, you should use the 7za utility which preserves owner/group of a file, unlike 7z, the -si option enables reading of files from stdin.

$ tar -cf - tecmint_files | 7za a -si tecmint_files.tar.7z

7. To restore a backup, use -so option, which will sends output to stdout.

$ 7za x -so tecmint_files.tar.7z | tar xf -

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

$ tar -cf - tecmint_files | 7za a -si -mx=9 tecmint_files.tar.7z

9. To update an existing archive file or remove 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>

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

$ 7za a -p{password_here} tecmint_secrets.tar.7z

For more information refer to the 7z man page, or go to the 7zip Homepage: https://www.7-zip.org/.

That’s all for now! In this article, we have explained 10 7zip (File Archive) command examples in Linux. Use the feedback form below to ask any questions or share your thoughts with us.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

4 thoughts on “10 7zip (File Archive) Command Examples in Linux”

  1. Can someone tell me how to do either one of the following:

    1. Shell script to convert ALL zip files to 7z format (origin zip files have folders with more zip files).
    2. A Nautilus (right-click script) to do the same as #1.

    I prefer option 2, but either will do.

    Regards,
    Brian

    Reply
  2. Does not even start with telling people how to 7zip a test.txt file, but a 7zip file into a .deb file or the other way around? Shallow, horrible guide, sorry for saying the truth.

    Reply

Leave a Reply to andrew Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.