.7z File Compression Command Reference (7z is not ZIP!)
We get Grok to write us a nice guide on using the .7z archiving and compression format. 7z EXCEEDS zip compression significantly however it does not have file repairing. You will need TOA, DAR or PAR2 for that!
- .7z is presumed to be the same as zip. It actually is not!
- .7z does NOT have error correction. You will need to either make two backups, or consider a archiving overlay that will add error correction such as TOA, PAR2, or DAR!
Debian Installation
sudo apt update
sudo apt install p7zip-fullFedora / Red Hat Installation
sudo dnf update
sudo dnf install p7zip p7zip-plugins- Full installation / compiling guide is here
Once it is installed you can inspect all it's capabilites - it has many!
7z iWill produce:
┌─[c@parrot]─[~]
└──╼ $7z i
7-Zip 25.01 (x64) : Copyright (c) 1999-2025 Igor Pavlov : 2025-08-03
64-bit locale=en_US.UTF-8 Threads:16 OPEN_MAX:1024, ASM
Libs:
0 : 25.01 : /usr/lib/7zip/7z.so
Formats:
0 C...F..........c.a.m+.. w...0 7z 7z 7 z BC AF ' 1C
0 ...................... APFS apfs img offset=32 N X S B 00
0 ...................... APM apm E R
0 ...................... Ar ar a deb udeb lib ! < a r c h > 0A
0 ...................... Arj arj ` EA
0 K.....O.....X......... Base64 b64
0 ......O............... COFF obj
0 ...F.................. Cab cab M S C F 00 00 00 00
0 ...................... Chm chm chi chq chw I T S F 03 00 00 00 ` 00 00 00
0 ...................... Compound msi msp doc xls ppt D0 CF 11 E0 A1 B1 1A E1
0 ....M................. Cpio cpio 0 7 0 7 0 || C7 q || q C7
0 ...................... CramFS cramfs offset=16 C o m p r e s s e d 20 R O M F S
0 .....G..B............. Dmg dmg k o l y 00 00 00 04 00 00 02 00
0 .........E............ ELF elf E L F
0 ...................... Ext ext ext2 ext3 ext4 img offset=1080 S EF
0 ...................... FAT fat img offset=510 U AA
0 ...................... FLV flv F L V 01
0 ...................... GPT gpt mbr offset=512 E F I 20 P A R T 00 00 01 00
0 ....M................. HFS hfs hfsx offset=1024 B D || H + 00 04 || H X 00 05
0 ...F.................. Hxs hxs hxi hxr hxq hxw lit I T O L I T L S 01 00 00 00 ( 00 00 00
0 ......O............... IHex ihex
0 ...................... Iso iso img offset=32769 C D 0 0 1
0 ...................... LP lpimg img offset=4096 g D l a 4 00 00 00
0 ...................... Lzh lzh lha offset=2 - l h
0 .......P.............. MBR mbr
0 ....M....E............ MachO macho CE FA ED FE || CF FA ED FE || FE ED FA CE || FE ED FA CF
0 ...................... MsLZ mslz S Z D D 88 F0 ' 3 A
0 ....M................. Mub mub CA FE BA BE 00 00 00 || B9 FA F1 0E
0 ...................... NTFS ntfs img offset=3 N T F S 20 20 20 20 00
0 ...F.G................ Nsis nsis offset=4 EF BE AD DE N u l l s o f t I n s t
0 .........E............ PE exe dll sys M Z
0 ...................... Ppmd pmd 8F AF AC 84
0 ...................... QCOW qcow qcow2 qcow2c Q F I FB 00 00 00
0 ...F.................. Rar rar r00 R a r ! 1A 07 00
0 ...F.................. Rar5 rar r00 R a r ! 1A 07 01 00
0 ...................... Rpm rpm ED AB EE DB
0 K..................... SWF swf F W S
0 ....M................. SWFc swf (~.swf) C W S || Z W S
0 ...................... Sparse simg img : FF & ED 01 00
0 ...................... Split 001
0 ....M................. SquashFS squashfs h s q s || s q s h || s h s q || q s h s
0 .........E............ TE te V Z
0 ...FM................. UEFIc scap BD 86 f ; v 0D 0 @ B7 0E B5 Q 9E / C5 A0 || 8B A6 < J # w FB H 80 = W 8C C1 FE C4 M || B9 82 91 S B5AB 91 C B6 9A E3 A9 C F7 / CC
0 ...FM................. UEFIf uefif offset=16 D9 T 93 z h 04 J D 81 CE 0B F6 17 D8 90 DF || x E5 8C 8C = 8A 1C O 99 5 89 a 85 C3 - D3
0 ....M.O............... Udf udf iso img offset=32768 00 B E A 0 1 01 00 || 01 C D 0 0 1
0 ...................... VDI vdi offset=64 10 DA BE
0 .....G................ VHD vhd c o n e c t i x 00 00
0 ...................... VHDX vhdx avhdx v h d x f i l e
0 ...................... VMDK vmdk K D M V
0 ...................... Xar xar pkg xip x a r ! 00
0 ...................... Z z taz (.tar) 1F 9D
0 CK..................... bzip2 bz2 bzip2 tbz2 (.tar) tbz (.tar) B Z h
0 CK.................m+.. .u..1 gzip gz gzip tgz (.tar) tpz (.tar) apk (.tar) 1F 8B 08
0 K.....O............... lzma lzma
0 K..................... lzma86 lzma86
0 C......O...LH......m+.. wu.n1 tar tar ova offset=257 u s t a r
0 C.SN.......LH..c.a.m+.. w...0 wim wim swm esd ppkg M S W I M 00 00 00
0 CK..................... xz xz txz (.tar) FD 7 z X Z 00
0 C...FMG........c.a.m+.. wud.0 zip zip z01 zipx jar xpi odt ods docx xlsx epub ipa apk appx P K 03 04 || P K 05 06 || P K 06 06 || P K 07 08 P K || P K 0 0 P K
0 K..................... zstd zst tzst (.tar) ( B5 / FD
CK.....O.....XC........ Hash sha256 sha512 sha384 sha224 sha512-224 sha512-256 sha3-224 sha3-256 sha3-384 sha3-512 sha1 sha2 sha3 sha md5 blake2s blake2b blake2sp xxh64 crc32 crc64 cksum asc
Codecs:
0 4ED 303011B BCJ2
0 EDF 3030103 BCJ
0 EDF 3030205 PPC
0 EDF 3030401 IA64
0 EDF 3030501 ARM
0 EDF 3030701 ARMT
0 EDF 3030805 SPARC
0 EDF A ARM64
0 EDF B RISCV
0 EDF 20302 Swap2
0 EDF 20304 Swap4
0 ED 40202 BZip2
0 ED 0 Copy
0 ED 40109 Deflate64
0 ED 40108 Deflate
0 EDF 3 Delta
0 ED 21 LZMA2
0 ED 30101 LZMA
0 ED 30401 PPMD
0 EDF 6F10701 7zAES
0 EDF 6F00181 AES256CBC
Hashers:
4 1 CRC32
0 4 1 CRC32
0 16 208 MD5
0 20 201 SHA1
0 32 A SHA256
0 32 231 SHA3-256
0 48 222 SHA384
0 64 223 SHA512
0 8 211 XXH64
0 8 4 CRC64
0 32 202 BLAKE2sp7z is superior to zip.
The ZIP format, introduced in 1989, remains the de facto standard for universal compatibility. It uses the DEFLATE algorithm (a combination of LZ77 and Huffman coding) for compression. By contrast, the 7z format, developed by the open-source 7-Zip project starting around 2000, employs more advanced algorithms, primarily LZMA or LZMA2, with optional support for PPMd, BZip2, and others.
7-Zip employs the LZMA/LZMA2 algorithm in its native .7z format, achieving substantially higher compression ratios than the DEFLATE method used by ZIP for most data types (typically 20–60% better reduction, depending on content). It also supports alternative methods (e.g., BZip2, PPMd) and other formats (ZIP, TAR, XZ). The examples below primarily use the .7z format with LZMA2 for optimal results. The default compression level is 5 (Normal); level 9 (Ultra) provides maximum compression at increased CPU and memory cost.
7z CRUSHES ZIP.
- We took an example text 'War and Peace' compressed it with zip level 9 then 7z max=9. The results were shocking - it compressed WNP 25% more than zip! - it compressed the txt by 75%!
-rw-rw-r-- 1 c c 995872 Feb 21 15:36 wnp.7z
-rw-rw-r-- 1 c c 3867598 Feb 21 15:35 wnp.txt
-rw-rw-r-- 1 c c 1324187 Feb 21 15:35 wnp.zip
┌─[c@parrot]─[~]
└──╼ $python -c "print(995872 / 1324187)"
0.7520629639167278
┌─[c@parrot]─[~]
└──╼ $python -c "print(995872 / 3867598)"
0.2574910836131366
┌─[c@parrot]─[~]25 Examples of Using .7z to Compress Files
The first 20 examples demonstrate compression operations using the 7z command-line tool. Examples 21–25 integrate rsync for efficient, resumable transfer of archives to remote systems. Each command appears in its own code block, followed by a clear explanation of the key parameters and their purpose.
Example 1: Compressing a single file
7z a archive.7z document.pdf
The a command adds files to an archive (creating it if absent). No additional switches apply the default compression level (5). This is suitable for simple, single-file archiving with strong LZMA2 compression.
Example 2: Compressing multiple files
7z a archive.7z file1.txt file2.txt file3.log
Files are listed explicitly after the archive name. The command adds them using default settings. This method efficiently groups a known, small set of files.
Example 3: Recursive compression of a directory
7z a -r archive.7z /path/to/directory/
The -r switch enables recursive inclusion of all subdirectories and files. This ensures a complete directory structure is archived, essential for backups.
Example 4: Recursive compression with maximum (Ultra) compression
7z a -mx=9 -r archive.7z /path/to/directory/
The -mx=9 switch selects Ultra compression level (highest ratio, LZMA2 default). Combined with -r, it minimizes archive size, ideal when storage is limited and time is secondary.
Example 5: Recursive compression with fastest compression
7z a -mx=1 -r archive.7z /path/to/directory/
The -mx=1 switch applies the fastest compression level. With -r, it prioritizes speed over ratio, appropriate for rapid archiving or when further compression occurs later.
Example 6: Storing files without compression
7z a -mx=0 -r archive.7z /path/to/directory/
The -mx=0 switch disables compression (store mode). Paired with -r, it bundles files without size reduction, useful for compatibility or pre-compressed content.
Example 7: Encrypting an archive with a password
7z a -p -r secure.7z /path/to/directory/
The -p switch enables AES-256 encryption and prompts for a password. With -r, it produces a secure, recursive archive, protecting sensitive data during storage or transfer.
Example 8: Updating an existing archive
7z u archive.7z /path/to/newfiles/*
The u command updates the archive by adding new files and replacing older versions. This supports incremental archiving without reprocessing unchanged content.
Example 9: Freshening files in an existing archive
7z u -freshen archive.7z
The -freshen switch (used with u) updates only files already present if newer versions exist. It maintains synchronization with minimal overhead.
Example 10: Moving files into an archive (delete originals)
7z a -sdel archive.7z /path/to/files/*
The -sdel switch deletes source files after successful addition. This conserves space when originals are no longer needed post-archiving.
Example 11: Recursive compression excluding specific patterns
7z a -r -x!*.tmp -x!*.log archive.7z /path/to/directory/
The -r enables recursion; -x!pattern excludes matching files. This produces a cleaner archive by omitting temporary or log files.
Example 12: Recursive compression including only specific file types
7z a -r -i!*.jpg -i!*.png archive.7z /path/to/directory/
The -r recurses; -i!pattern includes only matching files. This creates a targeted archive of designated types, ignoring others.
Example 13: Splitting an archive into multiple volumes
7z a -v50m multi.7z /path/to/directory/
The -v50m switch creates volumes of 50 MB maximum (suffixes: k, m, g). This aids distribution across size-limited media or networks.
Example 14: Recursive compression in quiet mode
7z a -bd -r archive.7z /path/to/directory/
The -bd switch disables the progress indicator. With -r, it runs silently, suitable for scripts or automated tasks.
Example 15: Recursive compression with detailed output
7z a -bb3 -r archive.7z /path/to/directory/
The -bb3 switch enables high verbosity (levels 0–3). Combined with -r, it provides detailed progress, useful for debugging.
Example 16: Testing archive integrity
7z t archive.7z
The t command tests CRC and structure integrity without extraction. It verifies archive reliability before use or transmission.
Example 17: Deleting files from an existing archive
7z d archive.7z "old/*.bak"
The d command deletes entries matching the pattern. This removes obsolete files without recreating the archive.
Example 18: Recursive compression preserving symbolic links
7z a -l archive.7z /path/to/directory/
The -l switch stores symbolic links as links (not dereferenced). With recursion implied, it preserves filesystem structure accurately.
Example 19: Creating an archive from a list file
7z a archive.7z @filelist.txt
The @ prefix reads filenames from the specified list file (one per line). This handles large or generated lists efficiently.
Example 20: Creating an archive from find output
find /path/to/directory -type f -name "*.txt" -print | 7z a -si texts.7z
find generates the file list; -si directs input from stdin. This builds a selective archive without manual specification.
Example 21: Recursive ultra compression followed by rsync transfer
7z a -mx=9 -r backup.7z /path/to/directory/ && rsync -avz backup.7z user@remotehost:/backups/
7z uses -mx=9 (Ultra) and -r (recursive). rsync applies -a (archive mode), -v (verbose), -z (transit compression). This creates a compact archive and transfers it efficiently.
Example 22: Rsync transfer of pre-compressed archive with progress and resume
rsync -avzP --partial backup.7z user@remotehost:/backups/
(Assumes prior creation with 7z.) Parameters include -a (archive), -v (verbose), -z (compression), -P (progress + partial/resume), --partial (keeps incomplete files). This ensures reliable transfer over unstable links.
Example 23: Rsync directory, then compress remotely
rsync -avz /local/directory/ user@remotehost:/remote/directory/ && ssh user@remotehost "7z a -mx=9 -r /remote/backup.7z /remote/directory/"
rsync uses -a, -v, -z. Remote ssh runs 7z with -mx=9 and -r. This shifts compression to the destination, reducing local load.
Example 24: Batch compressing multiple directories, then rsync
for d in dir1 dir2 dir3; do 7z a -mx=9 -r "${d}.7z" "$d/"; done && rsync -avz *.7z user@remotehost:/backups/
Loop creates Ultra-compressed archives recursively. rsync transfers them with -a, -v, -z. This automates batch processing and centralized storage.
Example 25: Ultra compression with move, rsync, and local cleanup
7z a -mx=9 -sdel -r temp.7z /path/to/directory/ && rsync -avzP temp.7z user@remotehost:/backups/ && rm temp.7z
7z applies -mx=9, -sdel (delete sources), -r. rsync uses -a, -v, -z, -P. Final rm removes the temporary archive post-transfer.
These examples offer a robust framework for leveraging 7-Zip's superior compression in local and networked scenarios. Adjust paths, archive names, and credentials to suit your environment.