Updated: 10 October 2026 · Applies to: 7-Zip 23.01 to 26.04 on Ubuntu 24.04 and 26.04, Debian 13, AlmaLinux 10, Rocky Linux 9 and Fedora 44
To use 7-Zip on Linux, install the 7zip package and run the 7z command. 7z a adds files to an archive and 7z x extracts an archive with its folders:
7z a backup.7z /var/www/site # add a folder to backup.7z (created if it does not exist) 7z x backup.7z -o/tmp/restore # extract into /tmp/restore (no space after -o) 7z x photos.zip # 7z also unzips ZIP files
We ran every command below in containers on our test server, mostly with 7-Zip 25.01 on Debian 13. The output is real; only the long version header is shortened.
1. Install 7-Zip
sudo apt install 7zip # Ubuntu, Debian sudo dnf install epel-release && sudo dnf install 7zip # AlmaLinux, Rocky Linux, RHEL sudo dnf install 7zip # Fedora
Versions we got: 7-Zip 23.01 on Ubuntu 24.04, 25.01 on Debian 13, 26.00 on Ubuntu 26.04, 26.02 on Rocky Linux 9 and 26.03 on AlmaLinux 10 (both from EPEL; without EPEL, dnf finds no 7zip package) and 26.04 on Fedora 44. This is the official 7-Zip code, which replaced the old p7zip port (last version 16.02): on Debian and Ubuntu, apt install p7zip-full now just installs 7zip. The command is 7z in every case.
The newest version (26.04 at the time of writing) is also available as a ready-made build from 7-zip.org. Unpack the .tar.xz file and you get 7zz (and 7zzs, a static build for systems that lack the shared libraries). It takes the same commands, so use ./7zz wherever this article says 7z.
2. Add files to an archive (7z a)
$ 7z a backup.7z site Scanning the drive: 2 folders, 3 files, 288918 bytes (283 KiB) Creating archive: backup.7z Add new data to archive: 2 folders, 3 files, 288918 bytes (283 KiB) Files read from disk: 3 Archive size: 14525 bytes (15 KiB) Everything is Ok
Useful variations:
- Add to an existing archive: run
7z a backup.7z newfile.txtagain with the same archive name and the new file is added to it.7z u backup.7z siteupdates files that changed on disk and adds new ones. - Make a ZIP file that Windows and macOS open without extra software:
7z a -tzip site.zip site - Compression level:
-mx=1is the fastest,-mx=9the strongest (and slowest). - Leave files out:
7z a backup.7z site '-xr!*.log'skips every.logfile in all subfolders. Keep the quotes so the shell does not touch the!. - Split into parts:
7z a -v100m backup.7z sitewritesbackup.7z.001,.002and so on. To extract, run7z x backup.7z.001with all parts in the same folder. - Remove a file from an archive:
7z d backup.7z site/log.txt - Password:
7z a -p -mhe=on secret.7z documentsasks for a password and encrypts the file names as well. See how to create and open a password-protected ZIP file.
3. Extract an archive (7z x and 7z e)
- Look inside first (optional):
$ 7z l backup.7z Date Time Attr Size Compressed Name ------------------- ----- ------------ ------------ ------------------------ 2026-10-09 18:58:32 D.... 0 0 site 2026-10-09 18:58:32 D.... 0 0 site/css 2026-10-09 18:58:32 ....A 7 14303 site/css/style.css 2026-10-09 18:58:32 ....A 17 site/index.php 2026-10-09 18:58:32 ....A 288894 site/log.txt
- Extract with the full folder structure into a folder of your choice. 7-Zip creates the folder if it is missing:
7z x backup.7z -o/tmp/restore
The path goes straight after
-o. With a space (-o /tmp/restore) 7-Zip stops withCommand Line Error: Too short switch: -o. Without-o, files go into the current folder. - Extract only some files: name them, or use a wildcard with
-r:7z x site.zip -o/tmp/out site/css/style.css 7z x backup.7z -o/tmp/out -r '*.php'
- Check an archive without extracting it:
7z t backup.7zends withEverything is Okwhen the archive is intact.
7z e is the other extract command: it puts all files into one folder and drops their subfolders. Use 7z x unless you really want that.
If a file already exists, 7-Zip asks (Y)es / (N)o / (A)lways / (S)kip all / A(u)to rename all / (Q)uit?. In scripts, answer in advance: -aoa overwrites everything, -aos skips existing files and -y says yes to all questions.
4. Unzip ZIP, RAR, ISO and other formats
- ZIP:
7z x file.zip -o/tmp/outworks likeunzip, and it also opens AES-encrypted ZIP files thatunzipcannot. - RAR: the Debian and Ubuntu
7zippackage leaves out RAR support. Install7zip-rar(Debian: non-free component, Ubuntu: multiverse) or use the official7zzbuild, which unpacks RAR according to its readme. - ISO, WIM, XZ, ZSTD, CAB and more:
7z ilists every format your build supports. - .tar.gz: 7-Zip unpacks one layer at a time, so
7z x site.tar.gzonly gives yousite.tar. Usetar xzf site.tar.gzinstead (see how to create and extract a tar file).
5. Errors and how to fix them
- Cannot open the file as archive / Is not archive:
ERROR: fake.7z Open ERROR: Cannot open the file as [7z] archive ERRORS: Is not archive
The file is not a 7z archive, whatever its name says. Check what it really is with
file fake.7z(ours saidASCII text; an error page saved by a failed download looks the same). Download it again, or rename it to the real type. - Unexpected end of archive: the archive is cut off, usually an incomplete download or upload, or a missing part of a split archive. Copy it again and compare its size with the original.
- ERROR: Wrong password or
Cannot open encrypted archive. Wrong password?: the password you typed is wrong. Leave out-pand 7-Zip asks for it without showing it on screen. - 7z: command not found: install the package from step 1. With the official download, the command is
7zz.
Good to know
- 7-Zip kept the permission bits in our test (a
750script came back asrwxr-x---), but not the owner: after extracting as root, the file belonged to root. For server backups that must keep owners, pack with tar first:tar cf - site | 7z a -si backup.tar.7z, and restore with7z x -so backup.tar.7z | tar xf -. - On Windows, the Add to archive window of 7-Zip does the same job as
7z a; according to the 7-Zip FAQ its Parameters field accepts the same-msettings as the command line. - For plain ZIP files you can also use
zipandunzip: see how to zip and unzip files in Linux.
Official documentation: 7-Zip (the download for Linux includes the full command-line manual in its MANUAL folder).