Commands.page Logo

How to Compress a Folder to 7z in Ubuntu Linux

This article provides a concise guide on creating .7z compressed archives from folders within the Ubuntu operating system. You will learn the necessary package installation and the specific command-line syntax required to perform the compression quickly.

To begin, you must install the required utility since Ubuntu does not include 7z support by default. Open your terminal and run the following command to install the full version of p7zip:

sudo apt update sudo apt install p7zip-full

Once installed, the basic syntax to compress a folder into a .7z archive is as follows:

7z a archive_name.7z /path/to/folder

In this command, 7z calls the program, a stands for add, archive_name.7z is the name of the file you want to create, and /path/to/folder is the location of the directory you wish to compress. For example, to compress a folder named “Documents” located in your home directory into a file called “backup.7z”, you would execute:

7z a backup.7z ~/Documents

The terminal will display the compression progress and list the files being added. Once the process completes, the .7z file will be available in your current working directory.