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>] [<file_names>...]
e.g., 7za a archive.7z files/

PARAMETERS

a
    Add files to archive (create or update)

d
    Delete files from archive

e
    Extract from archive (no full paths)

l
    List archive contents (short)

ls
    List archive contents (detailed)

t
    Test archive integrity

u
    Update existing archive

x
    eXtract with full paths

-t{Type}
    Set archive type: 7z, zip, gzip, bzip2, xz, tar

-mx={0-9}
    Compression level: 0 (store) to 9 (ultra)

-p{Password}
    Set password for encryption

-r
    Recurse subdirectories

-slt
    Set archive timestamp from latest file

-ssw
    Compress shared files

-v{Size}[b|k|m|g]
    Create volumes of specified size

-y
    Assume Yes to all queries

-ao{a|s}
    Overwrite: a (append), s (skip)

DESCRIPTION

7za is a standalone command-line version of 7-Zip, a free open-source file archiver with high compression ratios. It supports formats like 7z, XZ, BZIP2, GZIP, TAR, and ZIP. Designed for Unix-like systems, it's part of the p7zip package and excels in creating and extracting archives efficiently.

Key features include strong AES-256 encryption, solid archives for better compression, and LZMA/LZMA2 algorithms. Use it to add, extract, list, test, or update files in archives. It's lightweight, requiring no full 7-Zip installation, and handles large files well. Ideal for scripts, backups, and cross-platform archiving.

Common operations: compress directories into .7z files surpassing ZIP/GZIP ratios, or extract with full paths. Benchmarks show superior speed and size reduction compared to traditional tools.

CAVEATS

Unix version lacks self-extracting (SFX) support; limited Windows-specific formats like WIM. Password prompts insecure in scripts. High compression (-mx=9) is CPU-intensive. No Unicode paths on older systems.

SUPPORTED FORMATS

Packing: 7z, xz, zip, gzip, bzip2, tar.
Unpacking: 7z, xz, zip, gzip, bzip2, tar, Z, lzma.

EXAMPLE USAGE

7za a -t7z -mx9 -psecret backup.7z /home/user/
Compresses directory with ultra compression and password.
7za x archive.7z -o/output/dir
Extracts to specified directory.

HISTORY

Developed by Igor Pavlov as part of 7-Zip (1999). p7zip port (2004) added Unix support; 7za is standalone executable from p7zip-full. Evolved with LZMA2 (v4.57+), remains actively maintained for POSIX systems.

SEE ALSO

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

Copied to clipboard