7z: Extract and Create Archives in Linux

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

1672 views

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/

Tell us what you think:

  1. Understanding file permissions in Unix / Linux based systems, and how to make files immutable.
  2. How to search a directory and subdirectories for a given string of text in Linux with the grep command.
  3. Worth knowing in order to make a bootable USB memory stick with Windows on from Linux.
  4. This is why I decided to encrypt my new Flash Drive, and why I think you should too.
  5. About the problem with using sudo with graphical programs in Linux.

More in: Linux Tutorials