If you’ve been working with Debian 12, chances are you’ve already used tar or zip for packaging files. They work fine, but when you need smaller archives and stronger protection, nothing beats 7-Zip. The .7z format not only compresses better, it also supports AES-256 encryption and can even hide file names.
This guide will walk you through installing and using 7-Zip on Debian 12, show how recursive compression works, and explain why .7z is safer than .zip.
1. Installing 7-Zip on Debian 12
Update your package list and install the full package:
|
0 1 2 3 |
sudo apt update sudo apt install p7zip-full p7zip-rar -y |
p7zip-fullprovides the7zcommand with full archive supportp7zip-raris optional, adds.rarsupport
Verify the installation:
|
0 1 2 |
which 7z |
You should see /usr/bin/7z.
2. The Basics: Compress, Extract, List
The 7z tool is straightforward:
- Compress files or folders (recursive by default):
7z a archive.7z /path/to/folder - Extract an archive:
7z x archive.7z - List archive contents:
7z l archive.7z - Test archive integrity:
7z t archive.7z
When you compress a folder, 7-Zip automatically goes through all subfolders recursively. No extra flag is needed.
3. Why .7z Is Safer and Stronger Than .zip
Most people are familiar with .zip, but .7z offers significant security and efficiency advantages:
- Encryption strength:
.7zuses AES-256, a modern, industry-standard encryption method. By contrast,.zipoften defaults to ZipCrypto, which is weak and can be brute-forced quickly. Even when.zipuses AES, support across platforms is inconsistent. - Hidden file names: With
.7z, the-mheoption encrypts archive headers. This means even the file and folder names are hidden until the correct password is entered..zipcannot do this — file names are always visible. - Compression ratio:
.7zgenerally produces smaller files than.zip, saving space and bandwidth. - Cross-platform reality:
.zipis universally supported (Windows and macOS can open without extra tools)..7zmay require installing 7-Zip or PeaZip, but the tradeoff is much better security.
In short: use .7z when security and efficiency matter, and .zip only when compatibility is critical.
4. Safest Way to Archive a Folder
To compress a folder securely, recursively, and with verbose output:
|
0 1 2 |
7z a -t7z -p -mhe=on -bb3 archive.7z /path/to/folder |
What this does:
-t7zexplicitly uses the 7-Zip format-pprompts for a password (not stored in shell history)-mhe=onencrypts file headers so names and folders are hidden-bb3gives maximum verbosity, showing full progressarchive.7zis the output file/path/to/folderis the folder you want to compress (all subfolders included automatically)
You’ll be prompted for a password and confirmation before the process starts.
5. Extracting a Secure Archive
To restore the archive:
|
0 1 2 |
7z x archive.7z -bb3 |
You’ll be asked for the password before extraction begins.
6. Example in Action
Archiving /var/app/local/data into backup.7z:
|
0 1 2 |
7z a -t7z -p -mhe=on -bb3 backup.7z /var/app/local/data |
Extracting later:
|
0 1 2 |
7z x backup.7z -bb3 |
7. Quick 7-Zip Cheat Sheet
A handy reference for common commands:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Create archive (recursive by default) 7z a archive.7z /path/to/folder # Create archive with password + hidden names 7z a -t7z -p -mhe=on archive.7z /path/to/folder # Extract archive 7z x archive.7z # List archive contents 7z l archive.7z # Test archive integrity 7z t archive.7z |
8. Wrapping Up
On Debian 12, 7-Zip is the safest way to compress and protect your data. It compresses recursively by default, encrypts contents with AES-256, and with -mhe even hides file and folder names.
- Use
.7zwhen you care about security and compression. - Fall back to
.ziponly when you need universal compatibility.
With just a few commands, you can ensure your data is safe, private, and portable.