p7zip(1)
p7zip is a command-line file archiver that compresses and extracts 7z format archives with high compression ratios.
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
| Flag | What it does |
|---|---|
a | Add files to archive (create or update) |
e | Extract archive to current directory (loses folder structure) |
x | Extract with full paths preserved |
l | List contents of archive |
t | Test archive integrity |
-mx=N | Set compression level (0=none, 5=normal, 9=ultra) |
-mhe=on | Encrypt archive header (hide file names) |
-p | Set password for encryption or decryption |
-r | Recurse subdirectories when adding files |
-so | Write output to stdout |
-si | Read input from stdin |
-v | Create 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.7zCreate a heavily compressed, password-protected archive
7z a -mx=9 -p'MyPassword' secure.7z largefile.binTest archive integrity without extracting
7z t backup.7zArchive multiple directories and files with standard compression
7z a -r -mx=5 project.7z src/ docs/ *.txtExtract and pipe to tar (extracting tar-in-7z archives)
7z x archive.7z -so | tar xCreate multi-volume archive split into 1GB chunks
7z a -v1g backup.7z folder/