How to install and use 7zip in Ubuntu Linux

This tutorial explains how to install and use 7zip in Ubuntu 18.04 step by step in detail. 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 with practical example.

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 Zip fromat.

7zip supports following formats.
Compressing and Decompressing Decompressing only

7zip was developed for Windows platform. Officially it is available only for Windows platform. Since it releases its source code under 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 18.04

Connect system with internet and run 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.

p7zip installation

Verifying 7zip installation

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

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

verfiy 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.

7z command

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 use the output of man pages. Once directory and files are created, check their size by du –h command.

7z practice lab

Creating 7zip archive

To create an archive from a single file, use 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.

creating 7zip archive from single file

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

creating zip archive from multiple files

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

$7z a allfileofdir.7z testdir

creating archive from all files of directory

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

listing archive files

Extracting 7zip archive

To extract an archive, use 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 rm command. Once file is deleted, restore it back from archive with following command.

$7z e myarchvie.7z

extracting zip files

The e option extracts files without rebuilding original directory structure. Use x option instead of e option, to extract files with original directory path.

Deleting individual file of files from 7zip archive

To delete an individual file or files, use following command

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

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

$7z d multifiles.7z tf4

deleting files from archive

Updating individual file of files from 7zip archive

To add a new file or files in existing archive, use 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

updating files in archive

This way you can perform a lot of compression and decompression related tasks from 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 advance tool to manage system, instead of using this basic tool, you should use 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 Ubuntu Linux Tutorials How to install and use 7zip in Ubuntu Linux