How to install and use 7zip in Ubuntu Linux

This tutorial explains how to install and use the 7zip in Ubuntu Linux. Learn how to create a 7zip archive, add files in existing archive, list archive files, delete individual file or files from archive and extract files from archive in Ubuntu.

A brief overview of 7zip

7zip is a community based open source file archiver. While comparing with other popular file archivers, it provides higher compression ratio. For example its default format 7z provides 30-50% better compression ratio than the Zip format.

7zip supports following formats.

Compressing and Decompressing Decompressing only
7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM AR, ARJ, CAB, CHM, CPIO, CramFS, DMG, EXT, FAT, GPT, HFS, IHEX, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, QCOW2, RAR, RPM, SquashFS, UDF, UEFI, VDI, VHD, VMDK, WIM, XAR and Z

7zip was developed for Windows platform. Officially it is available only for the Windows platform. Since it releases its source code under the GPL license, some individual developers made a Linux version of 7zip from the original source code.

The linux version of 7zip is known as p7zip. Since p7zip is built from original source code of 7zip, it provides same features and functions. So far functionality is concern, both are same. The only point that you should concern is that, since p7zip is not developed and maintained by original 7zip developers, you cannot get any help and technical support from them. For help and support you have use to the support forum of Ubuntu.

Installing 7zip in Ubuntu

Connect system with Internet and run the following commands in terminal.

$sudo apt-get update
$sudo apt-get install p7zip-full

Type y and press enter key when it asks for confirmation.

installing 7zip in ubuntu linux

Verifying 7zip installation

Once installation is finished, to confirm the installation, you can use any one command or both commands from the following commands.

$sudo apt-qq list p7zip-full
$sudo dpkg -s p7zip-full | grep Status

verifying the installation

Using 7zip

To use 7zip at command prompt, following command syntax is used.

$7z [command option] [archive file name] [files]

Following table lists some important and frequently used command options with description.

Command option Action Description
a add To add files in archive
l list To list the contents of archive
u update To update the files in archive
e extract To extract files from archive without their full path
x extract To extract files from archive with their full path
d delete To delete files from archive

There is no need to memorize anything from above table. You can list all options and switches with description at command prompt by simply running 7z command. If 7zip is installed, 7z command provides all necessary information about this tool such as command syntax, command options and command switches.

7zip command options and argument

7zip practical examples

To understand 7zip more clearly, let’s take some practical examples. Create a folder named testdir and create five text files in it. To create text files, you can store the output of man command in text files. Once directory and files are created, check their size by du –h command.

lab setup for practice

Creating 7zip archive

To create an archive from a single file, use the following command

$7z a [archive name & format] [file name]

For example, following command creates an archive named myarchive with 7z format from a single file named tf5.

$7z a myarchive.7z tf5

You may use du –h command to compare the original file size with archive file size.

7zip add operation

To create archive from multiple files, use following command

$7z a [archive file name] [file name 1] [file name 2] [file name 3] [file name …]

For example following command creates an archive named multifiles.7z from three files named tf3, tf4 and tf5.

$7z a mutifiles.7z tf3 tf4 tf5

adding multiple files in zip

Following command creates an archive named allfileofdir.7z from all files of directory named testdir.

$7z a allfileofdir.7z testdir

7zip adding multiple files in single archive

Listing 7zip archive

To view or list all files and directories from an archive, following command is used

$7z l [archive file name]

For example, following commands lists all files and directories from archives named myarchive.7z and multifiles.7z

$7z l myarchive.7z
$7z l multifiles.7z

7zip listing archive file

Extracting 7zip archive

To extract an archive, use the following command

$7z e [archive file name]

In our practice lab, we created an archive named myarchvie.7z from a single file tf5. Let’s use that for this practice.

Delete the file tf5 with the rm command. Once file is deleted, restore it back from the archive with the following command.

$7z e myarchvie.7z

7zip extracting zip file

The option e extracts files without rebuilding original directory structure.

Use option x instead of option e, to extract files with original directory path.

Deleting individual file or files from 7zip archive

To delete an individual file or files, use the following command

$7z d [archive name] [file name1] [file name2] [file name3] [file name…]

For example following command deletes file tf4 from archive multifiles.7z

$7z d multifiles.7z tf4

updating archive file

Updating individual file or files from 7zip archive

To add a new file or files in existing archive, use the following command

$7z  u [archive name] [file name1] [file name2] [file name3] [file name…]

For example following command adds file tf1 in existing archive multifiles.7z

$7z u multifiles.7z tf1

deleting single file from archive

This way you can perform a lot of compression and decompression related tasks from the 7z command. Learning and using this command is easier than other regular linux commands.

This tool is intended for basic usages only. If you are a regular user and looking for a fast and easy to use tool, don’t search anymore. You will not find any tool better than it. If you are a network administrator and looking for an advanced tool to manage the system, instead of using this basic tool, you should use the tar command line utility which is native to linux and provides a lot of more functionality.

That’s all for this tutorial. If you need any assistance regarding this tutorial, please let me know. If you like this tutorial, please share it with friends from your favorite social network.

ComputerNetworkingNotes Linux Tutorials How to install and use 7zip in Ubuntu Linux