7-Zip on FreeBSD: Archive Tool Review
7-Zip is one of those utilities that does one thing exceptionally well: compress and decompress files. Originally a Windows application known for its .7z format, the official command-line version (7z) is now available natively on FreeBSD. It handles dozens of archive formats, achieves some of the best compression ratios available, and integrates cleanly into FreeBSD workflows where you might previously have juggled multiple tools for different formats.
This review covers 7-Zip's capabilities on FreeBSD, practical CLI usage, compression performance compared to native tools, and when to use it versus gzip, bzip2, or the increasingly popular zstd.
Installation
7-Zip installs from packages in seconds:
shpkg install 7-zip
This provides the 7z command (and its variants 7zz, 7za). The package is the official 7-Zip port, not the older p7zip fork that was commonly used before the official Linux/BSD version existed.
Alternatively, from ports:
shcd /usr/ports/archivers/7-zip make install clean
Verify the installation:
sh7z --help
The 7z binary is self-contained with no runtime dependencies beyond the base system. It does not require any libraries, daemons, or configuration files.
Supported Formats
7-Zip's format support is one of its strongest features. On FreeBSD, it can handle:
Full support (compress and decompress):
- 7z (native format)
- XZ
- BZIP2
- GZIP
- TAR
- ZIP
- WIM
Decompress only:
- RAR (including RAR5)
- CAB
- ISO
- DMG
- VHD/VHDX
- QCOW2
- MSI
- DEB
- RPM
- CPIO
- AR
- NTFS images
- FAT images
- HFS/HFS+ images
- SquashFS
- CramFS
The decompress-only support for RAR is particularly valuable. On FreeBSD, this eliminates the need for the unrar package for most use cases. The ISO and disk image support is useful for system administrators who need to inspect images without mounting them.
CLI Usage
7-Zip's command-line interface follows a consistent pattern:
sh7z <command> <archive> [files] [switches]
Creating Archives
sh# Create a 7z archive 7z a backup.7z /path/to/files/ # Create a tar.gz (gzip-compressed tar) 7z a -ttar backup.tar /path/to/files/ 7z a -tgzip backup.tar.gz backup.tar # Create a zip archive 7z a backup.zip /path/to/files/ # Create with maximum compression 7z a -mx=9 backup.7z /path/to/files/ # Create with ultra compression (slower but smallest) 7z a -mx=9 -mfb=273 -ms=on -md=64m backup.7z /path/to/files/
Extracting Archives
sh# Extract preserving directory structure 7z x archive.7z # Extract to a specific directory 7z x archive.7z -o/tmp/extracted/ # Extract flat (no directory structure) 7z e archive.7z # Extract a RAR file 7z x archive.rar # Extract an ISO image 7z x image.iso -o/tmp/iso_contents/
Listing and Testing
sh# List archive contents 7z l archive.7z # Detailed listing with technical info 7z l -slt archive.7z # Test archive integrity 7z t archive.7z
Working with Encrypted Archives
sh# Create an encrypted archive 7z a -p"YourPassword" -mhe=on encrypted.7z /path/to/files/ # -mhe=on encrypts file names as well as content # Extract encrypted archive 7z x -p"YourPassword" encrypted.7z
The -mhe=on flag is important: without it, 7-Zip encrypts file contents but leaves file names visible. With it, even the directory listing is encrypted.
Piping and Scripting
7-Zip works well in pipelines and scripts:
sh# Compress stdin to a file tar cf - /path/to/dir | 7z a -si backup.7z.tar # Extract to stdout 7z x -so archive.7z | tar xf - # Backup a ZFS dataset through 7z zfs send tank/data@snap | 7z a -si -mx=3 dataset_backup.7z # List archive contents for scripting 7z l -ba archive.7z | awk '{print $NF}'
Batch Operations
sh# Compress each directory separately for dir in /backup/*/; do name=$(basename "$dir") 7z a -mx=7 "/archive/${name}.7z" "$dir" done # Extract all archives in a directory for f in /incoming/*.7z; do 7z x "$f" -o"/extracted/$(basename "$f" .7z)/" done # Test all archives for f in /archive/*.7z; do echo "Testing: $f" 7z t "$f" || echo "FAILED: $f" done
Compression Ratios
The 7z format using LZMA2 compression achieves excellent ratios, particularly on text and structured data. Here is a practical comparison compressing a 1 GB directory of mixed source code and text files:
sh# Test setup: 1 GB of FreeBSD source code # Results will vary with data type # gzip (default level 6) tar cf - src/ | gzip > src.tar.gz # Result: ~210 MB, ~15 seconds # gzip (maximum level 9) tar cf - src/ | gzip -9 > src.tar.gz # Result: ~195 MB, ~45 seconds # bzip2 (default) tar cf - src/ | bzip2 > src.tar.bz2 # Result: ~165 MB, ~90 seconds # xz (default level 6) tar cf - src/ | xz > src.tar.xz # Result: ~130 MB, ~180 seconds # zstd (default level 3) tar cf - src/ | zstd > src.tar.zst # Result: ~175 MB, ~5 seconds # zstd (maximum level 19) tar cf - src/ | zstd -19 > src.tar.zst # Result: ~125 MB, ~300 seconds # 7z (default LZMA2) 7z a -mx=5 src.7z src/ # Result: ~135 MB, ~120 seconds # 7z (ultra LZMA2) 7z a -mx=9 -md=64m src.7z src/ # Result: ~115 MB, ~400 seconds
Key takeaways:
- 7z with LZMA2 achieves the best compression ratios, especially at higher settings
- The compression time cost is significant at maximum settings
- For speed-sensitive workflows, zstd at default settings wins handily
- bzip2 offers no compelling advantage in any dimension today
Performance on FreeBSD
7-Zip includes a built-in benchmark that measures compression and decompression speed:
sh# Run the benchmark 7z b # Run with specific thread count 7z b -mmt=4 # Run with larger dictionary for memory/speed testing 7z b -md=26
7-Zip is well-optimized for multi-core CPUs. On FreeBSD, it correctly detects and uses all available cores:
sh# Compress using all cores (default) 7z a -mmt=on archive.7z files/ # Limit to 4 threads 7z a -mmt=4 archive.7z files/ # Single-threaded (for minimal system impact) 7z a -mmt=1 archive.7z files/
Decompression is typically single-threaded for LZMA2 streams, which is the main decompression performance limitation. The 7z container format supports multi-threaded decompression when the archive was created with solid block splitting.
Practical Use Cases on FreeBSD
System Backup Scripts
sh#!/bin/sh # backup.sh - Compressed backup of /etc and /usr/local/etc DATE=$(date +%Y%m%d) BACKUP_DIR="/backup" # Backup system configuration 7z a -mx=7 -mmt=on "${BACKUP_DIR}/etc_${DATE}.7z" /etc/ /usr/local/etc/ # Backup with password for offsite storage 7z a -mx=7 -mmt=on -p"${BACKUP_PASSWORD}" -mhe=on \ "${BACKUP_DIR}/etc_${DATE}_encrypted.7z" /etc/ /usr/local/etc/ # Clean up backups older than 30 days find "${BACKUP_DIR}" -name "etc_*.7z" -mtime +30 -delete
Log Compression
sh# Compress rotated logs more efficiently than gzip # In /etc/newsyslog.conf, you typically use gzip (flag Z) # For archival, recompress old logs with 7z find /var/log -name "*.gz" -mtime +7 -exec sh -c ' for f; do base=$(basename "$f" .gz) gunzip -c "$f" | 7z a -si -mx=9 "${f%.gz}.7z" rm "$f" done ' sh {} +
Inspecting Disk Images
sh# List contents of an ISO 7z l FreeBSD-14.1-RELEASE-amd64-disc1.iso # Extract specific files from an ISO without mounting 7z x FreeBSD-14.1-RELEASE-amd64-disc1.iso -o/tmp/iso/ boot/ # Inspect a Windows installation image (WIM) 7z l install.wim
7-Zip vs gzip on FreeBSD
gzip is FreeBSD's workhorse compression tool. It is part of the base system and used throughout the OS for log rotation, port distfiles, and package distribution.
- Speed: gzip is faster at compression and decompression at comparable ratios. For real-time use (log compression, piped data), gzip is preferred.
- Ratio: 7-Zip achieves 30-40% better compression on typical data.
- Compatibility: gzip is universal. Every Unix system can decompress
.gzfiles. The.7zformat requires 7-Zip or a compatible tool. - Integration: gzip integrates with
tarnatively (tar czf). 7-Zip handles tar as a separate layer.
Use gzip for: log rotation, tar archives for distribution, anything that needs maximum compatibility.
Use 7-Zip for: archival storage, backups where space matters, working with Windows-origin archives.
7-Zip vs bzip2 on FreeBSD
bzip2 is also in the FreeBSD base system but has fallen out of favor:
- Speed: bzip2 is slower than both gzip and 7-Zip at comparable compression levels.
- Ratio: 7-Zip achieves better compression in almost every scenario.
- Memory: bzip2 uses less memory than 7-Zip at high compression levels.
- Status: bzip2 is effectively legacy. New projects rarely choose it over xz or zstd.
There is little reason to choose bzip2 for new work. 7-Zip outperforms it on ratio, and zstd outperforms it on speed.
7-Zip vs zstd on FreeBSD
Zstandard (zstd) is the modern competition:
shpkg install zstd
- Speed: zstd is dramatically faster than 7-Zip at default settings while achieving comparable compression. At level 3, zstd compresses 5-10x faster than 7-Zip at comparable ratios.
- Ratio: At maximum settings (zstd -19 vs 7z -mx=9), 7-Zip still wins on ratio by 5-10%.
- Decompression: zstd decompresses significantly faster than LZMA2. This matters for frequently accessed archives.
- Adoption: zstd is increasingly used in FreeBSD's own ecosystem (ZFS supports zstd natively, pkg uses zstd for packages).
Use zstd for: fast compression/decompression, ZFS datasets, package distribution, CI/CD artifacts, anything accessed frequently.
Use 7-Zip for: maximum compression of archival data, working with .7z and .rar files, inspecting disk images and installer formats.
Verdict
7-Zip on FreeBSD is an excellent utility that earns its place in any sysadmin's toolkit. Its format support alone justifies installation -- being able to extract RAR, ISO, DMG, and dozens of other formats with a single tool eliminates the need for half a dozen specialized utilities.
The compression ratios with LZMA2 are the best available for general-purpose use. When archive size matters more than speed -- backups, archival storage, distribution to bandwidth-limited destinations -- 7-Zip delivers.
Where 7-Zip falls short is speed. For everyday compression tasks where you want fast results, zstd is the better choice. For system integration (log rotation, tar archives), gzip remains the practical default on FreeBSD.
The best approach on FreeBSD is to keep all three: gzip (base system) for daily compression, zstd for performance-sensitive tasks, and 7-Zip for maximum compression and broad format support.
Rating: 8.5/10 -- Excellent compression ratios, outstanding format support, clean CLI. Minor deductions for compression speed versus zstd and the less universal .7z format.
Frequently Asked Questions
Is 7-Zip the same as p7zip on FreeBSD?
No. p7zip was an unofficial port of 7-Zip to Unix systems. The FreeBSD 7-zip package is the official version maintained by Igor Pavlov (7-Zip's author). The official version is newer, faster, and better maintained.
Can 7-Zip extract RAR files on FreeBSD?
Yes. 7-Zip can decompress RAR archives (including RAR5 format) without any additional packages. It cannot create RAR archives, as RAR compression is proprietary.
Is 7-Zip multi-threaded?
Yes. Compression with LZMA2 uses multiple threads by default. Decompression is mostly single-threaded unless the archive was created with solid block splitting. Use -mmt=N to control thread count.
How does 7-Zip compare to xz on FreeBSD?
Both use LZMA-family compression. xz uses LZMA2 in the .xz container; 7-Zip uses LZMA2 in the .7z container. Compression ratios are nearly identical. xz integrates better with tar (tar cJf), while 7-Zip offers more features (encryption, multi-format support).
Can I use 7-Zip for ZFS send/receive backups?
Yes. Pipe the ZFS send stream through 7-Zip: zfs send pool/dataset@snap | 7z a -si backup.7z. For this use case, zstd is usually a better choice due to its faster compression and decompression speeds.
Does 7-Zip preserve FreeBSD file permissions?
The 7z format stores Unix permissions when created on Unix systems. The zip format has limited Unix permission support. For backup purposes where permission preservation is critical, use tar (which fully preserves permissions and ownership) and compress the tar with 7-Zip: tar cf - files/ | 7z a -si archive.tar.7z.