7-Zip is known for its high compression ratio and strong AES-256 encryption. On Linux, it’s useful for exchanging archives with Windows users, opening .7z and .rar files, and creating password-protected archives. There are two command-line versions: the official 7-Zip for Linux (7zz), and the older community port p7zip (7z).

Install

# Debian 12 / Ubuntu 22.04+ (official 7-Zip)
sudo apt install 7zip            # provides 7z (and 7zz on some versions)

# older releases: p7zip
sudo apt install p7zip-full p7zip-rar

# RHEL / AlmaLinux (EPEL)
sudo dnf install epel-release && sudo dnf install p7zip p7zip-plugins

Check which command you have: 7z or 7zz. The options are the same.

Create an archive

7z a backup.7z /var/www/site                 # add a folder
7z a -mx=9 backup.7z /var/www/site           # maximum compression
7z a -tzip site.zip /var/www/site            # create a .zip instead
7z a -mmt=on backup.7z data/                 # use multiple threads

Compression levels: -mx=0 (store only) to -mx=9 (ultra). Higher levels use more CPU and RAM. On busy servers, run with nice. See process priority with nice.

Extract

7z x backup.7z                    # extract with full paths
7z x backup.7z -o/tmp/restore     # to a directory (no space after -o)
7z e backup.7z                    # extract all files flat (no directories)
7z l backup.7z                    # list contents
7z t backup.7z                    # test integrity

7-Zip can also extract .zip, .rar, .tar, .gz, .xz, .iso and many other formats.

Password protection (AES-256)

7z a -p -mhe=on secret.7z /home/alice/documents
  • -p prompts for a password (avoid typing the password on the command line, where it ends up in shell history and process lists).
  • -mhe=on also encrypts file names (headers), so nobody can list the contents without the password. That’s only available in the .7z format.

Zip encryption (-tzip -p) uses weaker ZipCrypto by default. Add -mem=AES256 for AES in zip files, which modern unzip tools support.

Split into volumes

For upload limits or email size caps:

7z a -v100m bigbackup.7z /srv/data       # 100 MB parts: .7z.001, .7z.002 …
7z x bigbackup.7z.001                    # extract (all parts in the same folder)

See also split large files.

7z vs tar.gz / tar.zst for server backups

  • .7z doesn’t store Unix permissions and ownership reliably. For system and web backups, use tar (optionally with zstd or xz), and encrypt separately if needed. See tar command examples and compression compared.
  • .7z is great for sharing archives, especially with Windows users, and for encrypted archives of documents.

A common pattern: tar first (preserves permissions), then 7z for encryption:

tar -cf - /var/www/site | 7z a -si -p -mhe=on site.tar.7z
7z x -so site.tar.7z | tar -xf - -C /restore

Common problems

  • “Unsupported compression method” for RAR files: install the RAR plugin (p7zip-rar), or use unrar. Newer RAR5 archives need a recent 7-Zip version.
  • Wrong password errors on zip files from Windows: the archive may use AES. Make sure your 7-Zip build supports it, and check the keyboard layout used for the password.
  • Archive lost Linux permissions: expected with .7z. Wrap a tar archive inside it instead, as shown above.
  • Slow on big folders: lower the compression level (-mx=5), or exclude already-compressed files (-xr!*.mp4).

Quick reference

Task Command
Create 7z a archive.7z dir/
Max compression -mx=9
Extract with paths 7z x archive.7z -o/dest
List / test 7z l / 7z t
Encrypt + hide names 7z a -p -mhe=on archive.7z dir/
Split -v100m

Related: zip and unzip on Linux and Linux checksums.

  • Linux
  • Compression
  • Command Line