Share via:

7z: Extract and Create Archives in Linux

How to use 7zip to make and extract archives from terminal.


Edited: 2019-12-03 17:52

Linux tutorial

In this tutorial, you can learn to use 7zip from a terminal to make and extract archives. There are also graphical tools to accomplish the same thing, but the terminal might be more useful on servers.

Below are some quick examples you can use. If you feel it is needed, you may read the rest of the article as well for more detailed instructions.

To create a .7z archive:

7z a new-archive.7z file1.txt file2.txt

To extract a .7z archive:

7z x some-archive.7z

Linux has build-in manuals (man pages) for most commands on the system. These can be accessed by typing man [command name] in a terminal.

Installing 7zip in Ubuntu

First, we should make sure to install 7zip so that we can use the 7z command. In Ubuntu, this can be done using apt:

sudo apt install p7zip-full

Create a new 7z archive

After installing 7zip, we may create a new archive like this:

7z a new-archive.7z file1.txt file2.txt

It also works with whole directories:

7z a new-archive.7z directory-name

Note. The above examples assume you are in the directory of the files. Full paths works as well.

See also: Absolute and Relative Paths

Extracting a 7z archive

To extract an archive in the current directory, we do like this:

7z x my-archive.7z

We can also specify a path:

7z x /home/MyUserName/