Learn 7zip Command Examples in Linux

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

10 7zip (File Archive) Command Examples in Linux 

7-Zip is a free open source, cross-platform, powerful, and fully-featured le 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.

Learn 7zip Command Examples in Linux


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

$ 7z a hyper.7z hyper_1.4.2_i386.deb

Create 7z Archive File in Linux

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

$ 7z e hyper.7z

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

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

$ 7z l hyper.7z

List 7z File Information

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

$ 7z t hyper.7z

Check 7z File Integrity

6. To backup a directory, you should use the 7za utility which preserves owner/group of a le, unlike 7z, the -si option enables reading of les 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 le or remove le(s) from an archive le, 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 le, use -p {password_here} ag 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/.

You might also like