LinuxCommandLibrary

7za

Create and extract archives

TLDR

[a]rchive a file or directory

$ 7za a [path/to/archive.7z] [path/to/file_or_directory]
copy

Encrypt an existing archive (including file names)
$ 7za a [path/to/encrypted.7z] -p[password] -mhe=[on] [path/to/archive.7z]
copy

E[x]tract an archive preserving the original directory structure
$ 7za x [path/to/archive.7z]
copy

E[x]tract an archive to a specific directory
$ 7za x [path/to/archive.7z] -o[path/to/output]
copy

E[x]tract an archive to stdout
$ 7za x [path/to/archive.7z] -so
copy

[a]rchive using a specific archive type
$ 7za a -t[7z|bzip2|gzip|lzip|tar|...] [path/to/archive.7z] [path/to/file_or_directory]
copy

[l]ist the contents of an archive
$ 7za l [path/to/archive.7z]
copy

Set the level of compression (higher means more compression, but slower)
$ 7za a [path/to/archive.7z] -mx=[0|1|3|5|7|9] [path/to/file_or_directory]
copy

SYNOPSIS

7za <command> [<switches>...] <archive_name> [<file_names>...] [<@listfiles...>]

PARAMETERS

<command>
    Specifies the primary action to perform. Common commands include a (add files to archive), e (extract files without full path), l (list archive contents), x (extract files with full paths), and d (delete files from archive).

-o<dir>
    Sets the output directory for extracted files. For example, -o/tmp/extracted.

-p<password>
    Sets the password for encrypting or decrypting an archive. For 7z archives, use with -mhe for header encryption.

-m<method>
    Sets compression method and parameters. Example: -mx=9 for Ultra compression, -mmt=on for multi-threading.

-t<type>
    Specifies the type of archive to create or extract (e.g., -t7z, -tzip, -ttar, -tgz, -tbz2, -txz).

-r
    Recurses subdirectories when adding files to an archive.

-sfx[<name>]
    Creates a self-extracting archive. An optional <name> can specify the SFX module to use.

-v<size>[b|k|m|g]
    Creates multi-volume archives with a specified volume size (e.g., -v10m for 10 MB volumes).

-y
    Assumes 'Yes' on all queries, useful for scripting and non-interactive operations.

-mx[0-9]
    Sets the compression level: 0 (Store/No compression), 1 (Fastest), ..., 9 (Ultra/Maximum compression).

-s
    Creates a solid archive (default for 7z format). Solid archives offer better compression for many small files but can make individual file extraction slower.

-mhe
    Enables header encryption for 7z archives when used with -p, hiding filenames and other metadata.

DESCRIPTION

7za is a powerful command-line utility, serving as a standalone version of the renowned 7-Zip archiver. It is widely recognized for its exceptionally high compression ratio, particularly when utilizing the 7z format with its advanced LZMA and LZMA2 algorithms. This tool boasts extensive support for various archive formats, enabling the unpacking of numerous types (including 7z, Zip, Gzip, Bzip2, Tar, XZ, Cpio, and Ar) and efficient packing for a key subset (such as 7z, Zip, Gzip, Bzip2, Tar, and XZ).

The standalone nature of 7za means it operates without external modules, making it highly portable and an ideal choice for minimalist Linux environments or scenarios requiring self-contained archive distribution. Key features include robust AES-256 encryption, the capability to create multi-volume archives, and support for self-extracting (SFX) archives. It stands as an indispensable tool for efficient data storage, secure backups, and streamlined file distribution.

CAVEATS

While 7za is highly capable, its design as a standalone executable means it might not support all archive formats for packing or unpacking that the full 7z command (which can dynamically load plugins) might. Notably, it typically does not support proprietary formats like RAR by default. Using extremely high compression settings (e.g., -mx=9) can be very resource-intensive, demanding significant CPU time and memory, potentially leading to considerably longer archiving durations. Solid archives (enabled by -s) can sometimes result in slower extraction of individual files, as the entire solid block up to the desired file might need to be decompressed.

COMPRESSION LEVELS (<B>-MX</B>)

7za provides a range of compression levels controlled by the -mx switch. Levels vary from 0 (Store), which performs no compression and is fastest, up to 9 (Ultra), which achieves the maximum possible compression. Higher levels, while yielding smaller archives, require significantly more time and system resources (CPU and RAM) during the compression process.

SOLID ARCHIVES (<B>-S</B>)

By default, 7z archives created by 7za are 'solid'. In a solid archive, all files are treated as a single continuous data stream, which can dramatically improve the compression ratio, especially for archives containing numerous small and similar files. However, a trade-off is that extracting a single file from a solid archive necessitates decompressing all data preceding that file within its solid block, potentially making individual file extraction slower compared to non-solid archives.

ENCRYPTION (<B>-P</B> AND <B>-MHE</B>)

7za supports robust AES-256 encryption. The -p switch is used to specify the password for archive encryption. For 7z archives, to ensure that file names and other metadata (like file sizes and modification dates) are also hidden, the -mhe (Master Header Encryption) switch must be used in conjunction with -p. Without -mhe, only the actual file content is encrypted, leaving the filenames exposed.

CROSS-PLATFORM AVAILABILITY

The 7-Zip project, including the 7za command-line utility, is highly cross-platform. Beyond its common use on Linux, it is also widely available and utilized on Windows, macOS, and other Unix-like operating systems. This broad compatibility ensures that archives created with 7za can be reliably extracted across different operating environments.

HISTORY

7-Zip was first introduced by Igor Pavlov in 1999. It rapidly gained prominence due to its open-source nature and the introduction of the highly efficient 7z archive format, powered by the LZMA compression algorithm. 7za emerged as the standalone command-line version of 7-Zip, specifically designed for portability and self-containment, without reliance on external dynamic libraries or plugins. This characteristic has made it a favored tool for inclusion in minimalistic Linux distributions, rescue disks, and environments where a full 7-Zip installation is impractical. Its continuous development focuses on enhancing compression ratios, improving speed, and broadening format compatibility.

SEE ALSO

7z(1), zip(1), unzip(1), tar(1), gzip(1), bzip2(1), xz(1)

Copied to clipboard