a (Add) command
Adds files to archive.
Examples
7z a archive1.zip subdir\
adds all files and subfolders from folder subdir to archive
archive1.zip .
The filenames in archive will contain subdir\ prefix.
7z a archive2.zip .\subdir\*
adds all files and subfolders from folder subdir to archive
archive2.zip .
The filenames in archive will not contain subdir\ prefix.
cd /D c:\dir1\
7z a c:\archive3.zip dir2\dir3\
The filenames in archive c:\archive3.zip
will contain dir2\dir3\ prefix,
but they will not contain c:\dir1\ prefix.
7z a Files.7z *.txt -r
adds all *.txt files from current folder and its subfolders to archive
Files.7z .
Notes
7-Zip doesn't use the system wildcard parser. 7-Zip doesn't
follow the archaic rule by which *.* means any file. 7-Zip treats
*.* as matching the name of any file that has an extension. To process
all files, you must use a * wildcard.
Switches that can be used with this command
-bb (Set output log level)
-i (Include)
-m (Method)
-p (Set Password)
-r (Recurse)
-sdel (Delete files after including to archive)
-sfx (create SFX)
-si (use StdIn)
-sni (Store NT security information)
-sns (Store NTFS alternate Streams)
-so (use StdOut)
-spf (Use fully qualified file paths)
-spm (Require path separator mark for directory path)
-ssw (Compress shared files)
-stl (Set archive timestamp from the most recently modified file)
-stx (Exclude archive type)
-t (Type of archive)
-u (Update)
-v (Volumes)
-w (Working Dir)
-x (Exclude)
See also
Commands:
d (Delete) ,
u (Update)
Switches:
-u (Update)
Notes from this site
Not part of the 7-Zip manual. Written by this site; examples checked with 7-Zip 26.04.
Quick examples (Linux, macOS, Windows)
On Linux and macOS the official console binary is 7zz; on Windows it is 7z. 7za and 7zr (reduced builds; 7zr handles only .7z) take the same command line. Use forward slashes and quote wildcards so the shell does not expand them. The format comes from the extension (.7z, .zip) or from -t .
7zz a archive1.zip subdir/
7zz a archive2.zip './subdir/*'
7zz a Files.7z '*.txt' -r
7zz a -mx=9 archive.7z project/
7zz a -mx=1 fast.zip project/
7zz a -v100m archive.7z project/
7zz a backup.7z project/ '-xr!node_modules' '-xr!*.tmp'
7zz u backup.7z project/ '-xr!node_modules' '-xr!*.tmp'
7zz a secure.7z -p -mhe=on project/
7zz a -tzip -mem=AES256 -p secure.zip project/
7zz a -ttar -so dummy.tar project/ | 7zz a -si -tgzip project.tar.gz
echo hello | 7zz a -si -tgzip hello.gz
7zz a -sdel old-logs.7z logs/
The first command stores names like subdir/b.txt; the second stores b.txt. A folder argument is added whole, hidden files included; -r is only needed for wildcards. -mx=9 is maximum compression; -mx=1 is fast, and -mx=0 only stores the files without compression, which is the fastest. -v100m splits into 100 MB parts. Plain -p prompts for the password (text after -p shows in ps and shell history). -mhe=on also encrypts file names, 7z only. The tar.gz line has two steps; with -so the first name is not written (leave it out and project/ becomes that name). -si has no file name to guess the format from, so give -tgzip or -t7z.
The u line after the a line adds only new and changed files to the existing archive (see u ). -sdel deletes the source files once the archive is written (the logs folder was gone in my test); try your script without it first. On Linux and macOS -snl stores symbolic links as links (tested; not in this manual).
Common mistakes
Writing -x!*.tmp without the r: it only matches at the top of the archive path, so project/x.tmp is still added. Use -xr! for any depth.
Expecting a to start a fresh archive: an existing archive keeps its other items and same-named files are replaced. Delete it first for a clean one, or use u to add only new and changed files.
Leaving ! unquoted: interactive bash can treat it as history expansion. Single-quote the whole switch.
Using .\subdir\* on Linux or macOS: a backslash is an ordinary character there.
Related pages