$linuxjunkies
>

p7zip(1)

p7zip is a command-line file archiver that compresses and extracts 7z format archives with high compression ratios.

UbuntuDebianFedoraArch

Synopsis

7z [OPTION]... [ARCHIVE_NAME] [FILE_OR_DIR]...

Description

p7zip is the Unix/Linux port of 7-Zip, a powerful archiver supporting the 7z format which typically achieves better compression than gzip or bzip2. It can create, extract, test, and list contents of 7z archives, as well as handle other formats like zip, tar, and rar.

The 7z format is notable for its high compression ratio, often 30-50% better than zip on text and source code. Use 7z as the command-line interface; p7zip installs the necessary binaries and libraries.

Common options

FlagWhat it does
aAdd files to archive (create or update)
eExtract archive to current directory (loses folder structure)
xExtract with full paths preserved
lList contents of archive
tTest archive integrity
-mx=NSet compression level (0=none, 5=normal, 9=ultra)
-mhe=onEncrypt archive header (hide file names)
-pSet password for encryption or decryption
-rRecurse subdirectories when adding files
-soWrite output to stdout
-siRead input from stdin
-vCreate volumes of specified size (e.g., -v100m)

Examples

Create a 7z archive from a directory with default compression

7z a backup.7z /home/user/documents/

Extract archive to /tmp/extracted/ preserving directory structure

7z x archive.7z -o/tmp/extracted/

List all files in the archive with sizes and dates

7z l archive.7z

Create a heavily compressed, password-protected archive

7z a -mx=9 -p'MyPassword' secure.7z largefile.bin

Test archive integrity without extracting

7z t backup.7z

Archive multiple directories and files with standard compression

7z a -r -mx=5 project.7z src/ docs/ *.txt

Extract and pipe to tar (extracting tar-in-7z archives)

7z x archive.7z -so | tar x

Create multi-volume archive split into 1GB chunks

7z a -v1g backup.7z folder/

Related commands