Skip to main content
The a (add) command creates new archives or adds files to existing archives.

Syntax

7z a [<switches>...] <archive_name> [<file_names>...] [@listfile]

Description

The add command is the primary method for creating archives. It can:
  • Create new archives
  • Add files to existing archives
  • Update existing files in archives with newer versions
  • Create multi-volume archives
  • Create self-extracting archives
  • Apply compression and encryption

Common Options

archive_name
string
required
Name of the archive to create or update. The archive type is determined by the file extension (e.g., .7z, .zip, .tar.gz) or by the -t switch.
file_names
string
Files or directories to add. Supports wildcards (* and ?). If omitted, adds files from current directory.
-t{Type}
string
Set archive type: 7z, zip, gzip, bzip2, tar, wim, xz, etc.Example: -t7z or -tzip
-mx{N}
number
default:"5"
Set compression level:
  • -mx0 = Store (no compression)
  • -mx1 = Fastest compression
  • -mx3 = Fast compression
  • -mx5 = Normal compression (default)
  • -mx7 = Maximum compression
  • -mx9 = Ultra compression
-m{Method}
string
Set compression method and parameters:
  • -m0=LZMA2 - Use LZMA2 method
  • -md={Size} - Dictionary size (16m, 32m, 64m, etc.)
  • -mfb={N} - Number of fast bytes (5-273)
  • -mmt={N} - Number of CPU threads
Example: -m0=LZMA2 -md=32m -mfb=64 -mmt=2
-mmt{N}
number
Set number of CPU threads for compression. Use -mmt=on for all available threads.Example: -mmt=4 or -mmt=on
-p{Password}
string
Set password for archive encryption. Omit the password to be prompted.Example: -pMySecretPass or -p (prompts for password)
-mhe=on
flag
Enable archive header encryption (7z format only). This hides file names and structure.
-v{Size}
string
Create multi-volume archives. Size can use suffixes: b (bytes), k (KB), m (MB), g (GB).Example: -v100m (100 MB volumes)
-r
flag
Recurse subdirectories. Include all files in subdirectories.
-x{Pattern}
string
Exclude files by pattern. Can be used multiple times.Example: -x!*.tmp -x!*.bak
-i{Pattern}
string
Include files by pattern.Example: -i!*.txt -i!*.doc
-sdel
flag
Delete files after compression (move to archive).
-ssw
flag
Compress files that are currently open/locked by other applications.
-ssc
flag
Set case-sensitive mode for file names.
-sfx{module}
string
Create self-extracting archive. Optionally specify SFX module.Example: -sfx7zCon.sfx
-w{path}
string
Set working (temporary) directory. Empty path means use system temp directory.
-si{name}
string
Read data from stdin. Optionally specify file name within archive.
-stl
flag
Set archive timestamp from the most recently modified file.
-snh
flag
Store hard links as links (not as separate files).
-snl
flag
Store symbolic links as links (not as file contents).

Examples

Create a basic 7z archive

7z a archive.7z files/
Output:
7-Zip 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20

Scanning the drive:
3 folders, 12 files, 45678 bytes (45 KiB)

Creating archive: archive.7z

Add new data to archive: 3 folders, 12 files, 45678 bytes (45 KiB)

Files read from disk: 12
Archive size: 23456 bytes (23 KiB)
Everything is Ok

Create archive with maximum compression

7z a -t7z -mx=9 archive.7z files/

Create password-protected archive with header encryption

7z a -p -mhe=on secret.7z files/
Prompts for password:
Enter password (will not be echoed):
Verify password (will not be echoed):

Create ZIP archive with normal compression

7z a -tzip archive.zip files/

Create multi-volume archive (100 MB volumes)

7z a -v100m archive.7z large_files/
Creates:
archive.7z.001
archive.7z.002
archive.7z.003
...

Add files with specific extension

7z a archive.7z *.txt -r

Exclude specific files

7z a archive.7z files/ -x!*.tmp -x!*.bak

Create archive and delete source files

7z a -sdel archive.7z files/

Create archive with specific compression method

7z a -t7z -m0=LZMA2 -mx=9 -md=64m -mfb=64 -mmt=4 archive.7z files/

Create archive from stdin

cat file.txt | 7z a -si archive.7z

Create self-extracting archive

7z a -sfx archive.exe files/

Update existing archive

7z a existing.7z newfile.txt

Create tar.gz archive (two-step compression)

7z a -ttar archive.tar files/
7z a -tgzip archive.tar.gz archive.tar
Or in one command:
tar -cf - files/ | 7z a -si -tgzip archive.tar.gz

Advanced Usage

Solid Archives

For maximum compression on similar files:
7z a -t7z -m0=lzma2 -mx=9 -ms=on archive.7z files/

Multiple CPU Threads

Use all available CPU cores:
7z a -mmt=on archive.7z files/

Custom Dictionary Size

Larger dictionary = better compression but more memory:
7z a -md=256m archive.7z files/
When adding files to an existing archive, 7-Zip updates files that have been modified and adds new files. Use the -u (update) command for more control over update behavior.
The -sdel switch permanently deletes source files after compression. Use with caution!
For best compression of text files, use:
7z a -t7z -m0=PPMd -mx=9 archive.7z textfiles/
PPMd algorithm works better for text than LZMA2.

Build docs developers (and LLMs) love