Archives

7z

Create, list, test, and extract 7-Zip archives.

archivecompressextract7zip

Additional Notes

7z is the command-line interface for 7-Zip archives. It can create, list, test, and extract archives in 7z and several other formats depending on the installed build.

Use it when you need strong compression, password-protected archives, or compatibility with files created by 7-Zip on Windows.

Syntax

7z command [options] archive [files...]

Parameters

  • command: Operation such as a, x, e, l, t, or d.
  • archive: Archive file to create, inspect, or extract.
  • files: Files or directories to add or process.
  • options: Compression, recursion, password, and output flags.

Common Commands

  • a: Add files to an archive.
  • x: Extract with full paths.
  • e: Extract files into the current directory without full paths.
  • l: List archive contents.
  • t: Test archive integrity.
  • d: Delete files from an archive.

Common Options

  • -r: Recurse into subdirectories.
  • -pPASSWORD: Use a password. Avoid placing passwords in shell history when possible.
  • -mhe=on: Encrypt archive headers for 7z archives.
  • -oDIR: Extract output into DIR. No space after -o.
  • -mx=9: Use high compression.
  • -y: Assume yes for prompts.

Examples

7z a backup.7z ./project

Create a 7z archive from a directory.

7z l backup.7z

List archive contents.

7z x backup.7z -o./restore

Extract with paths into ./restore.

7z t backup.7z

Test archive integrity.

Practical Notes

  • Use x instead of e when directory structure matters.
  • Quote filenames that contain spaces.
  • Some distributions provide this as p7zip, p7zip-full, or 7zip packages.