7Z Command-line explanation

Source: Internet
Author: User
Tags benchmark compact switches

The instructions for using the 7z.exe in the cmd window are as follows:

7-zip (A) 4.57 Copyright (c) 1999-2007 Igor Pavlov 2007-12-06

Usage:7za <command> [<switches> ...] <archive_name> [<file_names> ...]
[< @listfiles ...;]

<Commands>
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
<Switches>
-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
-scs{utf-8 | WIN | DOS}: Set CharSet for list files
-sfx[{name}]: Create SFX Archive
-si[{name}]: Read data from stdin
-slt:show Technical information for L (List) command
-so:write data to stdout
-ssc[-]: Set sensitive case mode
-ssw:compress Shared files
-t{type}: Set Type of archive
-V{SIZE}[B|K|M|G]: Create volumes
-u[-][p#][q#][r#][x#][y#][z#][!newarchivename]: Update options
-w[{path}]: Assign work directory. Empty path means a temporary directory
-x[r[-|0]]]{@listfile |! Wildcard}: EXclude filenames
-y:assume Yes on all queries

Instructions for use in Chinese are as follows:

Grammar
7z < command line > [< Options ...] < basic file name > [< parameter variable;
7z <command> [<switch> ...] <base_archive_name> [<arguments> ...] * G8 T1 {-L2 e) p% T ' V; A
< parametric variables >:: = < options > | < wildcard characters > | <File name > | < file list >
< options >::= < option tag >< option character >[< options;]
< option tag >:: = '/' | ‘-‘
< file list >:: = @{FileName} (@4 _; F R6 J. t+ A5 @

<arguments>:: = <switch> | <wildcard> | <filename> | <list_file>
<switch>::= <switch_symbol><switch_characters>[<option>]
<switch_symbol>:: = '/' | ‘-‘
<list_file>:: = @{filename}
Expressions within square brackets (the characters between "[" and "]") are optional. '? 2 k0 k/m* F. q$ C4 H
The expression in the title number (the character between "<" and ">") is an expression that must be replaced (and the parentheses are removed).
An expression
expression1 | expression2 | ... | expressionn* r-s: |-p/n& M9 C
Command lines and options are available in uppercase or lowercase letters.
The first command line must be a parameter variable with no option.
The input order of the options and other filenames can be disrupted.
Wildcard characters or filenames with spaces must be enclosed in quotation marks:
"Dir\program files\*" + r+ U2 k B ' z& U. N
Dir\ "Program Files" \*. M R V3 S/S
A wildcard is a keyboard character, such as an asterisk (*) or a question mark (?), when you execute an add file, release a file, select a file,When you delete an operation such as a file, you can use it to represent one or more characters. Wildcards are often used in place of one or more characters when you do not know the true character or if you do not want to type the full name.
7-zip Support andWildcard characters similar to Windows:
"*" can use asterisks instead of 0 or more characters.
“?” You can use a question mark instead of a single character in a name.
7-zip does not use the default method of the system to handle wildcards, so 7-zip does not support other wildcard rules, where * * is equivalent to all files in the system. 7-zip will treat it as a full file of any extension. Therefore, you must use the * wildcard character to process all files.
Example:
*.txt This will find (add, select ...) All files with the extension ". txt"/z9 x0} ' d, B, s# Z
? A * This will find (add, select ...) All files with a second letter "a"/f+ ^8 N7 s% B ' Q
*1* This will find (add, select ...) All files containing "1" 3 w# Q "f c* h E6 N
*.*.* This will find (add, select ...) All include "." The dual extension file
If there is no file name on the command line, the default wildcard "*" will be used. * K. J # R7 U) w7 n3 A6?
Restrictions on the use of wildcard characters and file names in the archive file:
Wildcards and filenames cannot include system drive characters or URLs. Each wildcard and filename path is treated as the full path from the drive letter to the current directory/The full path from the root directory of the compressed archive. In other words, the start part of the path (the character before the first slash ("\") must be a name or a wildcard. 1 [% e:w/v/g, l "T0 N
Wildcard characters and filenames cannot end with a slash ("\").
Wildcard characters can only appear in the last part of the full path. ' M ' Q '-v2 O; M2 I9 _$ G2 D, U "b
Example:
Dir1\*.cpp correct
C:\dir1\*.cpp error: cannot include drive letter in Path
Dir1\dir2\g?. TXT is correct; i7 q+ P) E2 F8 g
Dir1\d?r2\file1.txt Error: Wildcards can only be used with the last part of the path
File list: l z$}; P4 O
You can use the file list to bulk manipulate the files you want to manipulate. The filenames in the file must be separated by a space or another line. (If you use an empty space, each file must be quoted).
The 7-zip command line supports simultaneous operation of multiple file lists. 2 y+ K2 G9 g:p. X2 M ' Z
For example, here's a list of files "Listfile.txt" contains the following: "i! Z)}. C7 K/h4 G; U ' @+ Q
"My Programs\*.cpp" 5 V; @* F) U5]$ K3 H6 J! b* N
Src\*.cpp
Then we can enter the command:
7z a-tzip archive.zip @listfile. txt
Add all files with the "CPP" extension in the "My programs" and "SRC" directories to the compressed archive "Archive.zip".


Command line
command-line commands are not case-sensitive.
For more information about the command line, see syntax.
Command Point Reference
Command function description
A Add. M% Z1 A/g8 Y:s9 d* C
D Delete: J9 _ _2 ~$ W, W2 m:u
E Release-Y7 {! I _ (k$ y
L List 4 w& J5 K X4}+ y# A) d* k:s
T test. h:w& C4 ~-p* o+ @
U update
X full path release
& '-O (] M. T ' k x0 '
command line Options/}1 o6 H9 v9 B2 V9 q ' R y
Syntax v* Y, ' + p (K5 b
< options >::= < options _ Symbols >< Options _ characters >[< options;]
< options _ symbol >:: = '/' | ‘-‘
&ltswitch>::= <switch_symbol><switch_characters>[<option>]
<switch_symbol>:: = '/' | ‘-‘
On the command line, a complete selection consists of the specified options, hyphens (-), or slashes (/), and the symbol for the option cannot use abbreviations. , q$ P! D-o "H B" W/y3 _# D
Option names are case insensitive. Some options include parameter variables, which need to be case-sensitive.
The options can be used anywhere on the command line. ##

(refer to Greegree's article) give an example of a compressed file first:

7z a-t7z archive.7z *.exe *.dll-m0=bcj-m1=lzma:d=21-ms-mmt

Add *.exe and *.dll files to the solid compaction archive archive.7z. Use the LZMA compression algorithm, the 2 MB dictionary size, and the BCJ converter. Compression turns on multithreading optimizations, if available.

-ms The solid mode is set by default. It treats all files in a compressed file as a continuous stream of data in the creation of a solid-compacted archive model. In general, solid compression can increase the compression ratio, especially when adding a large number of small files
-MMT turns on multithreading mode by default.
The above two is understandable, but how can "-m0=bcj-m1=lzma:d=21" be explained?
Follow the instructions given in the Chinese documentation:
-M0=BCJ--The first alternative compression algorithm is BCJ
-m1=lzma:d=21--The second alternative compression algorithm is LZMA, which specifies the dictionary size as the default (2MB 1-time Square) 2MB.

If you want to use maximized compression, you can use the following parameter options:

7z a-t7z drivertest_1.7z "i:\t\t1\*"-mx=9-ms=200m-mf-mhc-mhcf-m0=lzma:a=2:d=25:mf=bt4b:fb=64-mmt-r

-t7z--The format of the compressed file is 7z
-mx=9-ms=200m-mf-mhc-mhcf-m0=lzma:a=2:d=25:mf=bt4b:fb=64-mmt
--Specify compression algorithm options
-mx=9--Set compression level to limit compression (default: LZMA max algorithm, MB dictionary size, bt4b Match finder, Word size 64, BCJ2 filter)
-ms=200m--Turn on solid mode and set the solid data stream size to 200MB.
-MF--Open the executable file compression filter.
-MHC--Turn on file header compression.
-MHCF--Turn on the file header to fully compress. The 7z version I'm using is 4.42>2.30.
-m0=lzma:a=2:d=25:mf=bt4b:fb=64
--The first alternative compression algorithm is LZMA, the compression level is the maximum compression, the LZMA algorithm uses a dictionary size of 2MB (5 square) 32MB, the algorithm's matching device is bt4b (required memory is dx9.5 + MB), the compact byte of the compression algorithm is the maximum mode of 64 bytes.
-MMT--Turn on multithreaded mode.
-R-recursively to all subdirectories.

7z Command Unzip the file example: unzip the file.7z file to the directory Mydir.

7z x "d:\File.7z"-y-aos-o "D:\Mydir"

Parameter description:

X: Extract files under full path

-Y: All confirmation options are specified think Yes (i.e. no confirmation prompt is present)

-aos: Skipping files that already exist

-o: Set Output directory

about the use of memory:

In general, WindowsXP uses at least 80~160MB of memory, in order to ensure that the system is operating properly, but also to leave enough of the remaining 32MB of physical memory.
So if it is 512MB of memory, then 7z compression uses a memory of (512-32-160) 320MB, using bt4b (D*9.5+34MB), so d=32mb.
If it is 256MB of memory, then 7z compression uses a memory of (256-32-120) 104MB, using bt4b (D*9.5+34MB), so d=8mb.
Thus, in the WindowsXP graphical interface to get a larger compression ratio, or expand the capacity of physical memory, or can be used in DOS run 32-bit programs, otherwise, regardless of your virtual memory or the system's disk cache settings are larger, you can only see the hard drive lights flashing to swap paging files.
Typically, larger dictionary files provide a high compression ratio. However, it is slower and requires more physical memory when compressing and decompressing: the physical memory used for compression is approximately 10 times times the size of the dictionary file, and the physical memory used to decompress is approximately equal to the dictionary file sizes.

Syntax format: (see 7-zip Help file for details, see Dizzy can skip, use to learn again)
7z <command> [<switch> ...] <base_archive_name> [<arguments> ...]

7z.exe each command has a different parameter <switch> see the Help file
<base_archive_name> name of the compressed package
<arguments> for file name, wildcard or file list support
A: Add a compressed package for the file, or create a new compressed package.

D: Remove the file from the archive package.

E: Extracted from the compressed package.

T: Test the compression package for errors.

U: Update the files in the compressed package.
Wherein, 7z is to the command line compression decompression program 7z.exe,<command> is 7z.exe contains the command, listed as follows:

A:adds files to archive. Add to Compact Package
A command available parameters:
-I. (Include)
-M (Method)
-P (Set Password)
-R (Recurse)
-SFX (Create SFX)
-si (use StdIn)
-so (use StdOut)
-SSW (Compress shared files)
-T (Type of archive)
-U (Update)
-V (Volumes)
-W (working Dir)
-X (Exclude)


B:benchmark

D:deletes files from archive. To delete a file from a compressed package
d Command Available parameters:
-I. (Include)
-M (Method)
-P (Set Password)
-R (Recurse)
-U (Update)
-W (working Dir)
-X (Exclude)

E:extract unzip the file to the current directory or to the specified directory
e Command Available parameters:
-ai (Include Archives)
-an (Disable parsing of Archive_name)
-ao (Overwrite mode)
-ax (Exclude Archives)
-I. (Include)
-O (Set Output Directory)
-P (Set Password)
-R (Recurse)
-so (use StdOut)
-X (Exclude)
-Y (assume Yes on all queries)

L:lists contents of archive.
T:test
U:update

X:extract with full paths to the current directory or to the specified directory using the complete path of the file
x Command Available parameters:
-ai (Include Archives)
-an (Disable parsing of Archive_name)
-ao (Overwrite mode)
-ax (Exclude Archives)
-I. (Include)
-O (Set Output Directory)
-P (Set Password)
-R (Recurse)
-so (use StdOut)
-X (Exclude)
-Y (assume Yes on all queries)
-M (Set compression Method) switch
Specifies the compression method.


Using 7-zip to implement batch processing command line compression and decompression function

Edit a. bat file; each line is written so that multiple directories can be suppressed continuously.
7z A-mx9-md64m-mfb=273-slp-ssw-v1024m-mmt=2-r
{Path and 7z file name} {The path and file name and path to be compressed can be filled in multiple}

Example: It is recommended to wrap the file name and path name in pairs of double quotes
7z a-mx9-md64m-mfb=273-slp-ssw-v1024m "Game" "D:\game\*.*"
Compress the d:\game\ in the ultra-mode 64m dictionary fb273 1024m mode per sub-volume

-MXN n=0~9; compression mode selection
Level Method Dictionary fastbytes matchfinder Filter Description
0 Copy No compression.
1 LZMA KB HC4 BCJ fastest compressing
3 LZMA 1 MB HC4 BCJ Fast compressing
5 LZMA MB BT4 BCJ Normal compressing
7 LZMA MB BT4 BCJ Maximum compressing
9 LZMA MB BT4 BCJ2 Ultra compressing-mdnm fill dictionary size such as fill 26 and fill 64m the same; see more memory can be filled, such as 128m dictionary
1024m Max

The maximum value for dictionary size is 1 GB = 2^30 bytes. Default values for LZMA is (MB) in normal mode, + (+ MB) in Maximum mode (-mx=7) and (+) in Ultra mode (-M x=9).

-mfb=n fill fastbytes size, this number will increase slightly more compression but slow down

-SLP (Set Large Pages mode); it will speed up compression, but start will be stuck down, this feature works with Windows 2003/xp x64

-SSW also compresses shared files

-V (Create Volumes) switch
Specifies volume sizes.
Syntax
-v{size}[b | k | m | g]

-mmt=n Multi-core options, such as dual-core fill 2


Command line compression decompression 7z

1) Introduction
7z, full name 7-zip, is an open source software. is currently recognized as the largest compression ratio of compression decompression software.
Home:http://www.7-zip.org/
Chinese home:http://7z.sparanoid.com/
command-line version download:http://7z.sparanoid.com/download.html
Main Features:
# New LZMA algorithm increases compression ratio in 7z format
# Supported formats:
* Compression/decompression: 7z, XZ, BZIP2, GZIP, TAR, ZIP
* Unzip only: ARJ, CAB, CHM, CPIO, DEB, DMG, FAT, HFS, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, RAR, RPM, UDF, VHD, WIM, XAR, Z

2) Exit code
0: normal, no errors;
1: Warning, no fatal error, for example some files are being used, not compressed;
2: Fatal error;
7: command-line error;
8: Not enough memory;
255: The user stopped the operation;

3) Using syntax
7z < command line > [< Options ...] < basic file name > [< parameter variable;

Expressions within square brackets (the characters between "[" and "]") are optional.
The expression in the title number (the character between "<" and ">") is an expression that must be replaced (and the parentheses are removed).

7-zip supports wildcard characters similar to Windows:
"*" can use asterisks instead of 0 or more characters.
“?” You can use a question mark instead of a single character in a name.
If you use only *,7-zip, it will be treated as a full file with any extension.

4) Commands and examples

A add files to the compressed archive.
7z a archive1.zip subdir\: Add all the files and subfolders under the SubDir folder to Archive1.zip, and the file name in Archived1.zip contains the subdir\ prefix.
7z a archive2.zip. \subdir\*: Add all the files and subfolders under the SubDir folder to Archive1.zip, and the file names in Archived2.zip do not contain subdir\ prefixes.
CD/D c:\dir1\
7z a c:\archive3.zip dir2\dir3\: The file name in Archiive3.zip contains the dir2\dir3\ prefix, but does not contain the C:\DIR1 prefix.
7z a files.7z *.txt-r: Add all the txt files in the current folder and its subfolders to files.7z.

B Test the CPU running speed and check for memory errors.

d Delete files from compressed archives.
7z d archive.zip *.bak-r: Removes all bak files from the archive.zip.

E release files from the archive to the current directory. Or to the specified output folder. Output folder settings can be changed by the-O (Set output folder) option. This command places all the freed files into a folder. If you want to use the full path to release the file, you must use the X (full path release) command.
7z e archive.zip: Releases all files from the compressed archive Archive.zip to the current folder.
7z e archive.zip-oc:\soft *.cpp: Release *.cpp files from compressed archive archive.zip to C:\soft folder.

L List Compressed archive contents.
7z L Archive.zip: Lists the contents of the compressed archive archive.zip.

T test the integrity of the compressed archive file.
7z T archive.zip *.doc: Test the integrity of *.doc files in a compressed archive archive.zip.

U replace older files with newer ones in compressed archive files.
7z u archive.zip *.doc: Update *.doc file in compressed archive archive.zip.

X in the current directory, use the full path to release the file from the compressed archive. Or to the specified output folder.
7z x archive.zip: Releases all files from the compressed archive Archive.zip to the current folder.
7z x archive.zip-oc:\soft *.cpp: Release *.cpp files from compressed archive archive.zip to C:\soft folder.

5) More Options

--Invalidates the "--" option switch "-" on the command line. This allows files with the file name beginning with "-" to be used on the command line.
7z T---archivename.7z: Test-archivename.7z compressed archive.

-I specifies that files or a class of files are attached when compressing. This option can add more than one type to an attachment.
I[<recurse_type>]<file_ref> where <recurse_type> is available for r[-| 0] (Specific-r option see back-R),<file_ref> can be @{ ListFile} |! {wildcard}.
7z A-tzip Src.zip *.txt-ir! Dir1\*.cpp: Add the *.txt file from the current directory, and the *.cpp file in the DIR1 directory and its subdirectories to the Src.zip compressed archive.

-x specifies that a file or a class of files is excluded from the operation. This option can exclude more than one type at a time.
X[<recurse_type>]<file_ref> where <recurse_type> is available for r[-| 0] (Specific-r option see back-R),<file_ref> can be @{ ListFile} |! {wildcard}.
7z a-tzip archive.zip *.txt-x!temp.*: Add all *.txt files except the temp.* file to the compressed archive archive.zip.

-o Specifies to release the output folder of the file. This option can only be used with the release command.
7z x archive.zip-oc:\doc: Releases all files from the Archive.zip archive to the C:\Doc folder.

-R Recursive Sub-directory option.
-R opens the recursive subdirectory. This option is used by default for commands such as E (release), L (list), T (test), X (full path release) that are manipulated in a compressed archive.
-r-close the recursive subdirectory. This option is used by default for all commands that need to scan disk files, such as a (add), D (delete), U (update), and so on.
-r0 Open the recursive subdirectory. However, it applies only to wildcard characters.
7z l archive.zip-r-*.doc: Lists the *.doc files in the root directory in the Archive.zip compressed archive.
7z a-tzip archive.zip-r src\*.cpp src\*.h: Adds *.cpp and *.h files from the SRC directory and its subdirectories to the Archive.zip compressed archive.

-t specifies the compressed file format. Specifies the compressed file format. They can be: Zip, 7z, RAR, Cab, gzip, bzip2, tar, or other format. The default value is 7z format.
7z a-tzip archive.zip *.txt: Add all *.txt files from the current directory to the compressed archive archive.zip using the ZIP format.

-Y invalidates most of the prompts when the 7-zip executes the command. You can use this option to block hints when files are overwritten in the E (release) and X (full path release) commands.
7z x src.zip-y: Releases all files from Src.zip. All overwrite hints will be blocked and all files of the same file name will be overwritten.

-v Specifies the sub-volume size.
{Size} [B | k | m | g]
Specify the volume size, which can be used in bytes, KB (1 kb=1024 bytes), MB (1 MB = KB), or GB (1 GB = 1024x768). If you specify only {Size},7-zip will treat it as a word.
7z a a.7z *.txt-v10k-v15k-v2m: Creates a a.7z volume compressed archive. The first is a volume of ten KB, the second is a KB, and all that remains is 2 MB.

-p Specifies the password.
7z x archive.zip-psecret: Release All files in the compressed archive archive.zip with the password "secret".

-AO specifies how to overwrite an existing file with the same name on the hard disk during the release.
Syntax:-ao[a | s | u]
-aoa directly overwrites the existing file without any hint.
-aos skips existing files, which are not overwritten.
-aou if a file with the same file name exists, the released file is automatically renamed. For example, the file file.txt will be automatically renamed to File_1.txt.
-aot if the file with the same file name exists, the existing file is automatically renamed. For example, the file file.txt will be automatically renamed to File_1.txt.
7z x TEST.ZIP-AOA: Releases all files from compressed archive test.zip without prompting to overwrite existing files directly.

-an does not parse the Archive_name zone in the command line. This option must be used with the-I (attach file) switch. For example, if you use a list file for compressed archives, you need to specify the-ai option, so you need to disallow parsing of the Archive_name area in the command line.
See-ai and-ax in the following example.

-AI specifies additional files, including compressed file filenames and wildcard characters. This option can attach more than one type at a time.
Ai[<recurse_type>]<file_ref> where <recurse_type> is available for r[-| 0] (Specific-r option see back-R),<file_ref> can be @{ ListFile} |! {wildcard}.
7z t-an-air!*.7z: Test *.7z Compressed files in the current directory and subdirectories.

-AX Specifies the compressed archive that must be excluded from the operation. This option can exclude more than one type at a time.
Ax[<recurse_type>]<file_ref> where <recurse_type> is available for r[-| 0] (Specific-r option see back-R),<file_ref> can be @{ ListFile} |! {wildcard}.
7z t-an-ai!*.7z-ax!a*.7z: Test *.7z compressed file except for a*.7z.

More infrequently used options can be viewed with help. For example:-M sets the compression algorithm;-scs sets the character set of the list file for the file to be compressed,-SEML sends the compression file by e-mail,-sfx creates a self-release file,-si reads data from the standard input,-so from output to standard output,-SLP sets the large memory mode;-SLT Displays technical information ;-SSC settings are case-sensitive;-SSW compresses the file being written;-u update option.

7Z Command-line explanation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.