7z: Create and Extract Archives with p7zip
7z is the p7zip CLI for creating and extracting .7z archives (and reading zip, tar, gzip, and more), with strong compression via -mx=9 and AES password protection via -p.
7z packs a directory into a single compressed, optionally encrypted archive. In CI it is handy for encrypted artifact bundles and for extracting the many formats p7zip understands.
What it does
7z is a subcommand-driven tool: a adds files to an archive, x extracts with full paths, e extracts flat, l lists contents, and t tests. It compresses with LZMA/LZMA2 by default and can AES-256 encrypt with -p. It reads and writes .7z and reads many other formats.
Common usage
7z a -mx=9 build.7z dist/ # create, max compression
7z a -p"$PASS" -mhe=on secrets.7z ./secrets # encrypt + hide names
7z x build.7z -o./out # extract with paths
7z l build.7z # list contents
7z t build.7z # test integrityOptions
| Flag / verb | What it does |
|---|---|
| a | Add files to (create) an archive |
| x | Extract with full paths |
| e | Extract to one directory, ignoring paths |
| l | List archive contents |
| -mx=<0..9> | Compression level; -mx=9 is maximum |
| -p<password> | Set/require an archive password (AES-256) |
| -mhe=on | Encrypt archive header (hide file names) |
| -o<dir> | Output directory for extraction (no space) |
In CI
Install with apt-get install -y p7zip-full (the -full package provides the 7z/7za binaries and more codecs). Use -p"$PASS" with a secret from the environment for encrypted artifact bundles, and add -mhe=on to also hide file names. -o takes no space: -o./out, not -o ./out.
Common errors in CI
"7z: command not found" means p7zip is not installed; apt-get install -y p7zip-full. "Wrong password?" on extract means the -p value is missing or incorrect. "Can not open the file as archive" means the file is corrupt or not a supported format. On minimal images only 7za or 7zr may exist (fewer codecs); install p7zip-full for the full 7z binary.