First of all, it’s better to add the 7zip installation path to the system environmental path, right click Computer > properties > Advanced system settings > tab Advanced > Environment variables… > under system variables double click Path > click new.copy the installation path

type 7z

7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]

 a: Add files to archive
 b: Benchmark
 d: Delete files from archive
 e: Extract files from archive (without using directory names)
 l: List contents of archive
 t: Test integrity of archive
 u: Update files to archive
 x: eXtract files with full paths
 -ai[r[-|0]]{@listfile|!wildcard}: Include archives
 -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
 -bd: Disable percentage indicator
 -i[r[-|0]]{@listfile|!wildcard}: Include filenames
 -m{Parameters}: set compression Method
 -o{Directory}: set Output directory
 -p{Password}: set Password
 -r[-|0]: Recurse subdirectories
 -t{Type}: Set type of archive

Command a. You can use the “a” command with the single letter a. This command stands for “archive” or “add.” Use it to put files in an archive.

Arguments: You have to specify the destination archive, and the source files (in that order).

Note: On the test system, “C:\Users\Sam” contains two files (file1.txt and file2.txt). The command puts those two files in an archive.

Tip: To open your archive, right click on it and select 7-Zip -> Open archive. The screenshot shows the files compressed in files.7z.

Example command line 1

C:\Users\Sam>7z a -t7z files.7z *.txt

7-Zip (A)  4.60 beta  Copyright (c) 1999-2008 Igor Pavlov  2008-08-19

Creating archive files.7z

Compressing  file1.txt
Compressing  file2.txt

Everything is Ok


Command d. We use the “d” command in 7-Zip command lines. This stands for delete. It allows you to remove a certain file (or set of files) from inside an archive.

Note: You will need this if you use huge archives and need to save time. This is from the manual.

Tip: You can also remove a single file from an archive with “d”. This is more useful when you do not have a solid archive.

Example d command line

7z d *.bak -r

7z:          use executable
d:           delete files delete from this archive
*.bak:       only match bak files
-r:          traverse all subdirectories

Command e. The “e” stands for extract, and it means to unzip or expand an archive. You must specify the source archive always, and may also specify a destination.

Info: The “e” command extracts everything to a specified directory. Another command “x” can preserve directory structures in archives.

Overwrite prompts: 7-Zip will always prompt you if there is a file it needs to overwrite to extract the new file.

However: This can be problematic if you are scripting or embedding 7za.exe. In that case, see the -y switch.

Example e command line

7z e

7z:          executable
e:           use extract command source archive you want to expand

Command l. The lowercase L is used to list the contents of archives. You probably will not need to use it often. I thought I would test it and show an example.

Next: This shows the listing of a solid archive. The originals are 27216 bytes and 3888 bytes. They compress down to 1030 bytes.

Example l command line

C:\Users\Sam>7za l files.7z

7-Zip (A)  4.60 beta  Copyright (c) 1999-2008 Igor Pavlov  2008-08-19

Listing archive: files.7z

Method = LZMA
Solid = +
Blocks = 1
Physical Size = 1202
Headers Size = 172

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2008-10-02 15:48:01 ....A        27216         1030  file1.txt
2008-10-02 15:47:45 ....A         3888               file2.txt
------------------- ----- ------------ ------------  ------------------------
                                 31104         1030  2 files, 0 folders

Command t. Here we use the “t” command in the 7z program. This command allows you to test the integrity of archives. It stands for ‘test’ and is much less useful than the “-t” switch.

Warning: Don’t confuse the two. This one is used for diagnostics. We usually want the hyphen “-t.”

Example t command line

7z t *.doc -r

7z:          use this executable
t:           test the specified archive the archive you want to test
*.doc:       test all these files in the archive
-r:          recurse all child directories

Command u. This stands for update. This command replaces old files in your archive with newer files. This prevents needing to decompress and recompress the entire archive.

Warning: The “u” command doesn’t work with solid archives. A solid archive is one where all the files are compressed together.

So: You cannot update specific files in solid archives with the “u” command. Solid archives are limited.

Example u command line

7z u *.doc

7z:          executable name
u:           update command archive you want to update files in
*.doc:       only update these files (Word documents)

Switch m. We can change the optimization settings in 7-Zip on the command line. This is the most important and useful option you can use.

Tip: It specifies the method of compression. Here I will show a bunch of options, and also some examples.

Compression levels:

Switch -mx0: Don't compress at all.
             This is called "copy mode."

Switch -mx1: Low compression.
             This is called "fastest" mode.

Switch -mx3: Fast compression mode.
             Will automatically set various parameters.

Switch -mx5: Same as above, but "normal."

Switch -mx7: This means "maximum" compression.

Switch -mx9: This means "ultra" compression.
             You probably want to use this.

Switch m, advanced. Here are advanced compression method (-m) switches. The first three are usually of limited use. My experience is that manual optimizations doesn’t produce big benefits.

Switch -mfb: Specifies number of fast bytes. Sometimes helps with “sparse” files. Don’t bother.

Switch -mpass: Number of passes for deflate compression. Don’t bother with this. Automatically set with levels.

Switch -md: This specifies dictionary size. It is automatically set, so don’t bother.

Switch -mmt: Enable multithreading. Use if you have quad-core and a huge archive. Specify “on” or “off”.

Command x. This command is like “e” except it preserves the full paths. If you have an elaborate or important directory structure, use this option. This would be most useful for backups.

Example x command line

7z x

7z:          executable name
x:           use the extract command the archive you want to extract all the files from

Switch t type. Here I show how to specify the archive type. Note that you can specify any file name you want for any type. But some extensions are recommended—they are standard.

Type switches

          Switch: -t7z
          Format: 7Z
Example filename: archive.7z (default option)

          Switch: -tgzip
          Format: GZIP
Example filename: archive.gzip, archive.gz

          Switch: -tzip
          Format: ZIP
Example filename: (compatible)

          Switch: -tbzip2
          Format: BZIP2
Example filename: archive.bzip2

          Switch: -ttar
          Format: TAR
Example filename: tarball.tar (UNIX and Linux)

          Switch: -tiso
          Format: ISO
Example filename: image.iso (may not be supported)

          Switch: -tudf
          Format: UDF
Example filename: disk.udf

Type switch examples. The 7-Zip manual shows the -tiso and -tudf switches. These are not the most common. Almost all of the examples in this document use -t switches.

Example a command lines

7z a -tiso archive.iso
7z a -tudf archive.udf

7z:                         executable name
a:                          add to archive
-tiso or -tudf:             format of archive to create
archive.iso or archive.udf: name of archive to create