7z (7-Zip) — Create and extract 7-Zip archives
Linux / File and disk management / 7z.html
A high-ratio archiver that handles 7z, zip, tar and many other formats.
Basic Information
| Command Name | 7z (7-Zip) |
|---|---|
| One-line Introduction | A high-ratio archiver that handles 7z, zip, tar and many other formats. |
| Provided by | 7-Zip / p7zip (package install) |
| Official Documentation | https://man7.org/linux/man-pages/man1/7z.1.html |
| Supported Operating Systems | Linux, Windows, macOS |
| Installation Status | Requires the p7zip-full or 7zip package |
| Category | Linux file and disk management (tags: compression, 7z, archive, zip) |
What is this command?
7z reads and writes its own 7z format along with zip, tar, gzip and others. Its LZMA-family compression gives a high ratio.
It supports passwords and split archives; a adds files and x extracts them. The format is detected from the file extension.
What problems does it solve?
- You need maximum compression for large data
- You want one tool for zip and 7z
- You are creating an encrypted archive
- You only want to list archive contents
Key features
Create an archive
The a command takes the archive name and the files.
- When to use: You are bundling several files
- What you get: A 7z archive
- Limitations: Higher compression levels use more CPU.
Extract
The x command extracts into the current directory.
- When to use: You need to use a distributed archive
- What you get: The original directory structure
- Limitations: It may prompt before overwriting.
List and test
l lists entries and t tests integrity.
- When to use: You want to inspect before extracting
- What you get: A file list and a corruption verdict
- Limitations: Encrypted archives require a password.
Installation and usage
Check whether it is installed
7z i | head -n 5
sudo apt install p7zip-full # Debian/Ubuntu sudo dnf install p7zip # Fedora
Real-world examples
Create an archive
Bundle a directory at maximum compression.
7z a -mx=9 backup.7z /home/user/data
Extract
Extract into a chosen directory.
7z x backup.7z -o/restore
List contents
List entries without extracting.
7z l backup.7z