Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Install and use 7zip on Linux
Linux is a popular open-source operating system that offers many advantages, such as being free, customizable, and secure. One of the challenges that Linux users face is finding the right tools for certain tasks, such as compressing and decompressing files. Fortunately, 7zip is a powerful and versatile compression tool that can help us with this task.
In this tutorial, we will walk through the process of installing and using 7zip in Linux. We will cover different ways to install 7zip, including via the command line and package manager, and provide step-by-step instructions. We will also explain the basic usage of 7zip, such as how to compress and extract files and explore some of the advanced features and options available.
What is 7zip?
7zip is a program that lets you compress and decompress files with ease. It supports a wide variety of file formats like 7z, ZIP, RAR, TAR, and more. Some of the unique features of 7zip include
High compression ratio with the native 7z format
Making files smaller so they take up less space on your computer
Splitting up large files into smaller ones
Adding a password to protect your files
Making self-extracting archives that can be opened without any special software
Installing 7zip on Linux
There are different ways to install 7zip on Linux. The most common method is using the command line package managers specific to your Linux distribution.
Debian/Ubuntu Systems
For Debian-based Linux distributions, such as Ubuntu or Debian, you can install 7zip using the apt package manager
sudo apt update sudo apt install p7zip-full
Red Hat/Fedora/CentOS Systems
For Fedora, CentOS, and other RPM-based distributions, use the following command
sudo dnf install p7zip
For older CentOS/RHEL systems with yum
sudo yum install p7zip
Arch Linux Systems
For Arch Linux and other Arch-based distributions, use the following command
sudo pacman -S p7zip
Using Graphical Package Manager
If you prefer to use a graphical interface, you can open your distribution's software center or package manager from the applications menu. Search for "p7zip" or "7zip", then click the install button to begin the installation process.
Basic Usage of 7zip
Compressing Files
To compress a file or directory using 7zip, use the a (add) option with the 7zip command followed by the name of the compressed file and the file to be compressed
7z a compressed_file.7z file_to_compress
For example, to compress a directory named "Documents" into a file named "documents.7z"
7z a documents.7z Documents/
When you execute this command, a new file named "documents.7z" will be generated containing a compressed version of the "Documents" directory.
Compressing Multiple Files or Directories
To compress multiple files or directories with a single command, separate them with spaces
7z a compressed_files.7z file1.txt file2.txt directory1/ directory2/
Extracting Files
To extract a compressed file using 7zip, use the x (extract) option followed by the name of the file to be extracted
7z x compressed_file.7z
For example, to extract the "documents.7z" file created earlier
7z x documents.7z
Extracting Files to a Specific Directory
To extract the contents of a compressed file to a specific directory, use the -o option followed by the path to the directory
7z x compressed_file.7z -o/home/user/Downloads/
Note: There should be no space between -o and the directory path.
Advanced Features
Password Protection
You can secure your compressed files by using encryption. Use the -p option followed by a password when compressing files
7z a -pmypassword Documents.7z Documents/
When extracting an encrypted archive, 7zip will prompt you for the password.
Splitting Archives
For large files, you can split archives into smaller parts using the -v option followed by the desired size
7z a -v10m Documents.7z Documents/
This creates multiple files (Documents.7z.001, Documents.7z.002, etc.) of 10MB each.
Custom Compression Levels
Use the -mx option followed by a number from 0 to 9 to set compression levels
| Level | Speed | Compression |
|---|---|---|
| 0 | Fastest | No compression |
| 1 | Fast | Low compression |
| 5 | Normal | Default compression |
| 9 | Ultra | Maximum compression |
Example for maximum compression
7z a -mx9 Documents.7z Documents/
Common 7zip Commands
| Command | Description |
|---|---|
7z l archive.7z |
List contents of archive |
7z t archive.7z |
Test archive integrity |
7z d archive.7z file.txt |
Delete file from archive |
7z u archive.7z file.txt |
Update archive with file |
Conclusion
7zip is a powerful and versatile compression tool that offers excellent compression ratios and supports multiple formats. With its command-line interface, you can easily compress, extract, and manage archives on Linux systems. The advanced features like password protection, archive splitting, and custom compression levels make it suitable for both basic and professional use cases.
