LinuxCommandLibrary

p7zip

Compress/decompress 7z archives

TLDR

Archive a file, replacing it with a 7zipped compressed version

$ p7zip [path/to/file]
copy

Archive a file keeping the input file
$ p7zip [[-k|--keep]] [path/to/file]
copy

Decompress a file, replacing it with the original uncompressed version
$ p7zip [[-d|--decompress]] [compressed.ext].7z
copy

Decompress a file keeping the input file
$ p7zip [[-d|--decompress]] [[-k|--keep]] [compressed.ext].7z
copy

Skip some checks and force compression or decompression
$ p7zip [[-f|--force]] [path/to/file]
copy

SYNOPSIS

7z <command> [<switches>...] [<archive>...] [<files>...]
e.g., 7z a archive.7z file.txt
7z x archive.7z

PARAMETERS

a
    Add files to archive

b
    Benchmark

d
    Delete files from archive

e
    Extract files without paths

l
    List archive contents

p
    Print content of .7z.sfx

r
    Repair damaged archive

t
    Test archive integrity

u
    Update archive

x
    eXtract with full paths

-ai![-]
    Include/exclude archives

-ax[-]
    eXclude archive directories

-ao{a|s|t|u}
    Set output overwrite mode

-an
    Disable archive name field

-bb[0-3]
    Set output log level

-bd
    Disable progress indicator

-bk
    Disable working dir cleaning

-bt
    Benchmark

-i!
    Include filenames

-mx[0-9]
    Set compression level (0=store,9=ultra)

-mfb=[32|64|258]
    Set fast bytes

-ms[=on|off]
    Enable solid mode

-o{dir}
    Set output directory

-p{pass}
    Set password

-r[-]
    Recurse directories

-sa{c|e|p}t
    Set archive timestamp

-sc{s|e}{i|f|d}
    Set compression method

-scc{UTF-8|WIN}
    Set charset

-sdel
    Delete after compress

-sfx{path}
    Create SFX archive

-si{path}
    Read from stdin

-sl[]
    Set large pages

-snh
    Disable header

-sni
    Disable indent

-snl
    Disable long names

-so
    Write to stdout

-spd
    Disable wildcard matching

-spe
    Eliminate dup file paths

-spf
    Use fully qualified names

-ssc[-]
    Set sensitive case

-ssw
    Compress shared files

-stl
    Set archive timestamp from latest

-stx{list}
    Exclude file patterns

-t{type}
    Set archive type

-u[-][p#][q#][g#][x#]
    Update options

-v{size}m
    Create volumes

-wa{s|a}
    WinAttrs importance

-w{dir}
    Set working directory

-x{list}
    Exclude patterns

-y
    Assume Yes to all

-z{file}
    Read options from file

DESCRIPTION

p7zip is the Unix port of 7-Zip, a high-performance file archiver with superior compression ratios. It supports formats like 7z, ZIP, GZIP, BZIP2, TAR, XZ, and more, offering creation, extraction, testing, and management of archives.

Key features include AES-256 encryption, multi-threading for faster processing, solid archiving for better compression, and Unicode support. The package provides 7z (full-featured) and 7za (standalone, lighter binary without SFX modules).

Ideal for backups, software distribution, and handling large files on Linux/Unix systems. Compression outperforms gzip/bzip2 in many cases, especially for multimedia. Usage mirrors Windows 7-Zip CLI but with POSIX compatibility. Install via apt install p7zip-full on Debian/Ubuntu.

CAVEATS

Complex syntax with many switches; 7za lacks wildcard/exclude in some modes; high memory use for solid/ultra compression; no built-in progress bar without -bd.

COMMON EXAMPLES

7z a -t7z archive.7z dir/ – create 7z archive.
7z x archive.7z – extract.
7z t archive.7z – test.

SUPPORTED FORMATS

7z, XZ, ZIP, GZIP, BZIP2, TAR, WIM, ARJ, CAB, CHM, CPIO, CramFS, DEB, DMG, FAT, HFS, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, RAR*, SquashFS, UDF, VHD, VMDK, WIM, XAR, Z.

HISTORY

p7zip project began in 2005 by Mohamed Aly as port of 7-Zip 4.58 to POSIX. Maintained until 2016 (v16.02), now community forks like p7zip-compat track Igor Pavlov's 7-Zip upstream. Widely used in distros; replaced by upstream 7zz in newer Linux.

SEE ALSO

tar(1), gzip(1), bzip2(1), xz(1), unzip(1), rar(1)

Copied to clipboard