0% found this document useful (0 votes)
278 views16 pages

7-Zip Command Line User Manual

7-Zip is a command line utility that provides file compression and decompression functionality. It supports the ZIP file format and can compress files into ZIP archives with better compression ratios than other commercial archiving tools like PKZIP and WinZip. The manual describes the commands, switches, and syntax for using 7-Zip from the command line to add, delete, extract, list, test, and update files in ZIP archives.

Uploaded by

Muppets Channel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
278 views16 pages

7-Zip Command Line User Manual

7-Zip is a command line utility that provides file compression and decompression functionality. It supports the ZIP file format and can compress files into ZIP archives with better compression ratios than other commercial archiving tools like PKZIP and WinZip. The manual describes the commands, switches, and syntax for using 7-Zip from the command line to add, delete, extract, list, test, and update files in ZIP archives.

Uploaded by

Muppets Channel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 16

User's Manual

Command Line Version

7-Zip

Version 2.30

Contents
--------

Contents
Introduction
Compression ratio results
Zip format compatibility
Command line syntax
Commands
Switches
FAR support
Registration
Final comments

Introduction
------------

Note: Full version of User's Manual is placed in file "7-zip.chm".

7-Zip contains three clients modules:

- Plugin for Windows Explorer


- Plugin for FAR Manager
- Console version.

File "7z.exe" is a command line version of 7-Zip.


7z.exe is 32-bit console program for Windows 95/98/ME/NT/2000.
7z.exe uses other modules from 7-Zip package.

Compression ratio results


-------------------------

Compression ratio results are very dependent upon the data used for
the tests. We compared 7-Zip with some of the leading zip-compatible
commercial archivers: PKZIP 2.04g, WinZip 7.0.

FILE SET: The Canterbury Corpus (11 files totaling 2,810,784 bytes,
popular file set used to compression rates).

Archiver Compressed size Ratio

7-Zip -mx 676284 100%


PKZIP 2.04g -ex 726047 107%
WinZip 7.0 (Max Compression) 731499 108%
ZIP format compatibility
------------------------

7-Zip creates fully ZIP compatible archives. It means that


everyone can decompress these files by any ZIP compatible decompression
utility. During compression 7-Zip can use one of the following ZIP
compression methods:

* 0 - Store
* 8 - Deflate

Current version of the 7-Zip can extract any files from ZIP archive that
were compressed with one of the following methods:

* 0 - Store
* 6 - Implode
* 8 - Deflate

Files compressed with other ZIP compression methods can't be extracted by


current version of the 7-Zip. But supported methods are the most popular
now and it causes 7-Zip can decompress the most of ZIP archives. For
extracting files compressed with non-supported methods you must use some
other ZIP utility.

Since all ZIP compression methods supported by 7-Zip compression engine


also are supported by 7-Zip decompression engine then any ZIP archive
created by 7-Zip can further be decompressed by 7-Zip.

Current version of the 7-Zip also doesn't support multivolume archives, the
most of the SFX archives.

Command line syntax:


--------------------

7z <command>[<switch>]<base_archive_name>[<arguments>...]

<arguments> ::= <switch> | <wildcard> | <filename> | <list_file>


<switch> ::= <switch_symbol><switch_characters>[<option>]
<switch_symbol> ::= '/' | '-'
<list_file> ::= @{filename}

Expressions in square brackets (between '[' and ']') are optional.

Expressions in curly braces ('{' and '}') means that instead that
Expression (including braces) must be used some string.

Expression

expression1 | expression2 | ... | expressionN

means that any (but only one) from these expressions must be specified.

Commands and switches can be entered in upper or lower case.

Command is the first non-switch argument.


The "base_archive_name" must be the first filename on the command line
after the command.

The switches and other filenames can be in any order.

Wildcards or filenames with spaces must be quoted:

"Dir\Program files\*"

Dir\"Program files"\*

Switch options can be combined to save command line length. However, some
switch options take optional string arguments and therefore, must be the
last option in a combined argument token string because 7-Zip accepts the
rest of the argument token as the optional argument.

7-Zip uses wild name matching similar to Windows 95:

* '*' means a sequence of arbitrary characters.


* '?' means any character.

Examples:

"*.txt" means all files with an extension of


".txt"

"?a*" means all files with a second


character of "a"

"*1*" means all names that contains


character "1"

"*.*.*" means all names that contain two "."


characters

The default wildcard "*" will be used if there is no filename/wildcard in


command line.

Restrictions for wildcards and filenames for archiving files:

* Wildcards and filenames can't contain disk name or network name. Every
wildcard/filename path is treated as path from current directory on
disk and as path from root directory in archive. In other words, the
first part of path (letters before first slash ('\') symbol) always
must be name or wildcard.
* Wildcards and filenames can't be ended by slash ('\') symbol
* Wildcards can contain wildcard characters ('*' and '?') only in last
part of path.

Examples:

Dir1\*.cpp OK

c:\Dir1\*.cpp ILLEGAL: path contains disk name

Dir1\Dir2\g?.txt OK

Dir1\D?r2\file1.txt ILLEGAL: there is a wildcard char in


non last part

These restrictions do not act to filenames and directory names used not as
archiving files.

List file
---------

You can supply one or more filenames or wildcards for special list files
(files containing lists of files). The filenames in such list file must be
separated by space, tab or new line symbol(s). Wildcards or filenames with
spaces must be quoted.

Multiple list files are supported.

For example, if contents of file "listfile.txt" is the following:

"My programs\*.cpp"

Src\*.cpp

then command

7z a -tzip archive.zip @listfile.txt

adds to archive "archive.zip" all "*.cpp" files from directories "My


programs" and "Src"

Commands:
---------

ID Description Related Switches

a Add -i, -m, -r, -t, -u, -w, -x

d Delete -i, -m, -r, -u, -w, -x

e Extarct -i, -o, -p, -r, -x, -y

l List -i, -r, -x

t Test -i, -r, -p, -x

u Update -i, -m, -r, -t, -u, -w, -x

x Extract -i, -o, -p, -r, -x, -y


with full
paths

a: Add files to archive


-----------------------

This command allows to add files to archive.

Examples:
7z a -tzip archive.zip subdir\*

archives all files in directory "subdir".

7z a -tzip archive.zip "Program files\*" -r

archives all files in directory "Program files" and subdirectories.

See also: d, u, -u

Related switches: -i, -m, -r, -t, -u, -w, -x

d: Delete files from archive


----------------------------

This command allows you to delete files from the archive. These deleted
files are physically removed from the archive.

Example:

7z d archive.zip *.bak

See also: a, u, -u

Related switches: -i, -m, -r, -u, -w, -x

e: Extract files from archive


-----------------------------

This command will extract one or more files from the archive to the current
directory or to the output directory if specified. 7-Zip will prompt the
user before overwriting existing files unless the user specifies the "-y"
switch. If the user gives a "no" answer, 7-Zip will prompt must file be
extracted to other filename. Then a "no" answer skips file and "yes"
prompts for new filename.

7-Zip accepts the following responses:

* "Yes"
* "No"
* "Always" sets 7-Zip to assume YES for ALL subsequent queries of the
same class
* "Skip" sets 7-Zip to assume NO for ALL subsequent queries of the same
class
* "Quit"

Abbreviated responses such as "y", "n", "a", "s" and "q" are allowed.

Example:

7z e archive.zip -oc:\soft *.cpp

extracts all files ending in ".cpp" to subdirectory "c:\soft".

See also: x
Related switches: -i, -o, -p, -r, -x, -y

l: List contents of archive


---------------------------

List contents of archive.

Example:

7z l archive.zip *.txt

lists all "txt" files.

Related switches: -i, -r, -x

t: Test integrity of archive


----------------------------

Test archive files. This command performs a dummy file extraction, writing
nothing to the output stream, in order to validate the specified file(s).
7-Zip uses a 32 bit CRC to validate the contents of the files.

Example:

7z t archive.zip *.doc

tests all files ending in ".doc".

Related switches: -i, -p, -r, -x

u: Update files to archive


--------------------------

Update older files in the archive and add files that are new to the
archive.

Example:

7z u archive.zip *.doc

See also: a, d, -u

Related switches: -i, -m, -r, -t, -u, -w, -x

x: eXtract files with full pathname


-----------------------------------

This command extracts one or more files from the archive to their full
paths in the current directory or to the output directory if specified.

Example:

7z x archive.zip -oc:\soft -r *.cpp

extracts all files ending in ".cpp" from all archive subdirectories to


directory "c:\soft".

See also: e

Related switches: -i, -o, -r, -x, -y

Switches:
---------

ID Description Related
commands

-i Include filenames a, d, e, l, t, u, x

-m Set Method a, d, u

-o Set Output directory e, x

-p Set Password e, t, x

-r Recurse subdirectories a, d, e, l, t, u, x

-t Set type of archive a

-u Update options a, d, u

-w Assign Work directory a, d, u

-x Exclude filenames a, d, e, l, t, u, x

-y Assume Yes on all e, x


queries

-i: Include filenames


---------------------

Format:

-i[<recurse_type>]<file_ref>

<recurse_type> ::= r[- | 0]


<file_ref> ::= @{listfile} | !{wildcard}

This switch specifies additional include filenames and wildcards.

<recurse_type> Specifies how wildcards and file


names specified in this switch must
be used. If this option is not
assigned then global value, assigned
by -r switch will be used. For more
details see specification of -r
switch

{listfile} Specifies name of list file. See List


file description

{wildcard} Specifies wildcard or filename

Multiple include switches are supported.

Example:

7z a -tzip src.zip *.txt -ir!DIR1\*.cpp

adds all "*.txt" files from current directory and all "*.cpp" files from
directory "DIR1" and from all it's subdirectories.

See also: -r, -x

Related commands: a, d, e, l, t, u, x

-m: set compression Method


--------------------------

Format:

-m <method_parameters>

This switch specifies compression method.

Format of this switch is depended from archive type.

Zip

-m0 "Store" method. Files will be copied to archive


without compression. Archiving with -m0 method is
much faster than with other methods.

-mx Maximize Ratio. This switch sets the best compression


method. It can require additional amount of RAM and
compressing process can be slower.

GZip

-mx Maximize Ratio.

7z

Read full version of User's Manual, placed in file "7-zip.chm"

Examples:

7z a -tzip archive.zip *.jpg -m0

adds all "*.jpg" files to archive without compression.

Related commands: a, d, u
-o: set Output directory
------------------------

Format:

-o{dir_path}

This switch specifies destination directory where files are to be


extracted.

{dir_path} Specifies the destination


directory path. It's not required
path end with a backslash.

This switch works only with extraction commands.

Example:

7z e archive.zip dir1\a.doc -oc:\Docs

-p: set Password


----------------

Format:

-p{password}

This switch specifies password.

{password} Specifies password.

Example:

7z x archive.zip -psecret

extracts all files from "archive" using password "secret".

Related commands: e, t, x

-r: Recurse subdirectories


--------------------------

Format:

-r[- | 0]

This switch specifies method of treating wildcards and filenames assigned


in command line.

-r Enable recurse subdirectories. This


option is default for all commands
that matches files only within
archive: e, l, t, x

-r- Disable recurse subdirectories.


This option is default for all
commands that can scan files on
disk: a, d, u

-r0 Enable recurse subdirectories only


for wildcard names.

Examples:

7z l archive.zip -r- *.doc

lists all "*.doc" files in archive that belong root archive directory.

7z a -tzip archive.zip -r src\*.cpp src\*.h

adds all "*.cpp" and "*.h" files from directory "src" and all it's
subdirectories.

See also: -i, -x

Related commands: a, d, e, l, t, u, x

-t: set Type of archive


-----------------------

Format:

-t{archive_type}

Specifies the type of archive.

{archive_type} Specifies the type of archive.

Example:

7z a -tzip archive.zip -tzip

adds all files from current directory to zip archive "archive.zip".

Related commands: a, d, u

-u: Update options


------------------

Format:

-u[-]<action_set>[!{new_archive_name}]

<action_set> ::= <state_action>...

<state_action> ::= <state_type><action_type>

<state_type> ::= p | q | r | x | y | z | w

<action_type> ::= 0 | 1 | 2
This switch specifies how to update files in archive and (or)
how to create new archives.

- Disable any updates in base


archive.

{new_archive_name} Specifies path of the new


archive, which must be created.
All other options in this
switch will refer to this new
archive.

If not assigned, then all other


options in this switch will
refer to base archive of
command

Term "base archive" means archive assigned by "base_archive_name" string in


command line. See Command line syntax

Description of <state_type>:

For each unique filename there are 6 variants of state:

<state_type> State condition Disk Archive

p File exists in Exists,


archive, but but isn't
isn't wildcarded wildcarded
by archive
command.

q File exists in Not Exists


archive but exists
doesn't exist on
disk.

r File doesn't Exists Not exists


exist in archive
but exists on
disk.

x File in archive Older Newer


is newer than
file with same
name on disk.

y File in archive Newer Older


is older than
file with same
name on disk.

z File in archive Same Same


is same as file
with same name on
disk.

w Can not be detected what file is newer


(times are the same, sizes are different)

Description of <action_type>:

For each of the <state_type> you can specify action what do you wish:

<action_type> Description

0 Ignore file (don't create item in new


archive for this file)

1 Copy file (copy from old archive to


new)

2 Compress (compress file from disk to


new archive)

Any update command (a, d, u) can be assigned in these terms:

p q r x y z w

Disk any Not Exists Older Newer Same ?


exists

Exists,
Archive not Exists Newer Older Same ?
wildcarded

d Copy

a Copy Copy Com Com Com Com Com

u Copy Copy Com Copy Com Copy Com

"Empty" cell means 0 (Ignore).

"Copy" cell means 1 (Copy from base archive).

"Com" cell means 2 (Compress from disk).

If you don't specify "!{newArchiveName}", then all options will refer to main
archive (archive assigned in command line after command).

If you specify "{!newArchiveName}", then 7-Zip also will create a new archive
with specified name. 7-Zip can create any number of new archive during one
operation.

By default, for each new archive <action_set> is set as action set of main
command (there are 3 different action sets for commands: a, d, u). You can
overload any. <state_action>

Example:
7z u exist_archive.zip -u- -up0q0x2z0!update.zip *.cpp

creates new archive "update.zip" and writes to this archive all "*.cpp"
files from current directory that differs from files in archive
"exist_archive.zip". Archive "exist_archive" will not be changed.

Related commands: a, d, u

-w: assign Work directory


------------------------

Format:

-w [{path}]

This switch specifies working directory for temporary base archive. By


default, 7-Zip builds a new base archive file in the same directory as the
old base archive file. By specifying the "-w" switch, you can specify the
working directory where the temporary base archive file will be built.
After the temporary base archive file is built, it is copied over the
original archive and deleted. If <path> is not assigned, then 7-Zip will
use Windows temporary directory.

Example:

7z a -tzip archive.zip *.cpp -wc:\temp

Related commands: a, d, u

-x: Exclude filenames


--------------------

Format:

-x[<recurse_type>]<file_ref>

<recurse_type> ::= r[- | 0]


<file_ref> ::= @{listfile} | !{wildcard}

This switch specifies what filenames or (and) wildcards must be excluded


from operation.

For full option description of this switch see -i Include switch


description.

-i[r[-|0]]@listfile|!wildcard

Multiple exclude switches are supported.

Example:

7z a -tzip src.zip *.txt -x!temp.*

adds all "*.txt", except files with "temp" name, to archive "src.zip".

See also: -i, -r


Related commands: a, d, e, l, t, u, x

-y: assume Yes on all queries


----------------------------

Format:

-y

This switch disables most of the normal user queries during 7-Zip
execution. You can use this switch to suppress overwrite queries in the "e"
and "x" commands.

Example:

7z x src.zip -y

extracts all files from archive "src.zip". All overwrite queries will be
suppressed and files on disk with same filenames as in archive will be
overwritten.

Related commands: e, x

FAR support
-----------

The "FAR Manager" is a very good file manager. It facilitates a large


number of operations with files, folders and archives under Windows 95 and
Windows NT operating systems. It works in text mode. You can download "FAR
Manager" from sites:

http://www.rarsoft.com

There are two ways to use 7-Zip with FAR Manager:


- Via 7-Zip FAR Plugin (it's recommended way).
- Via standard MultiArc Plugin

7-Zip FAR Plugin


~~~~~~~~~~~~~~~~
7-Zip FAR Plugin is first level plugin for FAR Manager, like
MultiArc plugin. It very fast extracts and updates files in
archive, since it doesn't use external programs. It supports
all formats supported by 7-Zip: ZIP, RAR, CAB, GZIP, BZIP2 and TAR.

To install 7-Zip FAR Plugin:


1) Create "7-Zip" folder in "...\Program Files\Far\Plugins" folder.
2) Copy all files from "...\Program Files\7-Zip\Far" folder to created folder.
3) Restart FAR.

You can open archives with one of the following ways:


- Pressing "Enter".
- Pressing "Ctrl-PgDown".
- Pressing "F11" and selecting "7-Zip" item.

You can create new archives with 7-Zip by pressing "F11" and
selecting "7-Zip (add to archive)" item.
If you think that some operations with archives is better to do with
MultiArc Plugin, you can disable 7-Zip plugin via
"Options / Pligin configuration / 7-Zip". In such mode opening archives
by pressing Enter and Ctrl-PgDown will start MultiArc Plugin. And if
you want to open archive with 7-Zip, press "F11" and select "7-Zip" item.

Using command line 7-Zip via MultiArc Plugin


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you want use 7-Zip via MultiArc Plugin you must


register file "far7z.reg".
If you want to cancel using 7-Zip by MultiArc, just remove lines that contain
7-Zip (7z) program name from "HKEY_LOCAL_MACHINE\SOFTWARE\Far\Plugins\MultiArc\ZIP"
registry key:

Registration
------------

7-Zip is free software distributed under the GNU LGPL.


However, if you like 7-Zip and want to support further
development, please donate some money to 7-Zip Project.
You can do it using credit card or other payment methods.

To donate, please visit page

http://www.7-zip.org/donate.html

Final comments:
---------------

Full version of User's Manual is placed in file "7-zip.chm".


That file is in HTML Help format.

If you will disclose any bugs in program or errors in documentation,


please, send some report to the author.

The official page of the 7-Zip can be accessed at:

http://www.7-zip.org

You may freely send your comments and suggestions to Igor Pavlov, the
author of the 7-Zip:

E-mail:
support@7-zip.org

WWW:
http://www.7-zip.org

Igor Pavlov
End of document

You might also like