Tip:For convenience and so you don't need to change environment paths, put the 7za.exe file in your user directory.
Next:Open the Windows console and test the 7za.exe program out with a few commands. Type in the exe name 7za and this will display.
Grammar:We see the grammar we need to use with 7za.exe. The "command" is the main verb.
Switches:Then you specify optional switches, the archive name (source or destination) and files. My user directory is "C:\Users\Sam\".
7-Zip default output7-Zip (A) 4.60 beta Copyright (c) 1999-2008 Igor Pavlov 2008-08-19Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...] [<@listfiles...>]
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.
C:\Users\Sam>7za a -t7z files.7z *.txt7-Zip (A) 4.60 beta Copyright (c) 1999-2008 Igor Pavlov 2008-08-19ScanningCreating archive files.7zCompressing file1.txtCompressing file2.txtEverything is OkC:\Users\Sam>
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.
7z d archive.zip *.bak -r7z: use executabled: delete filesarchive.zip: delete from this archive*.bak: only match bak files-r: traverse all subdirectories
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.
7z e archive.zip7z: executablee: use extract commandarchive.zip: source archive you want to expand
Next:This shows the listing of a solid archive. The originals are 27216 bytes and 3888 bytes. They compress down to 1030 bytes.
C:\Users\Sam>7za l files.7z7-Zip (A) 4.60 beta Copyright (c) 1999-2008 Igor Pavlov 2008-08-19Listing archive: files.7zMethod = LZMASolid = +Blocks = 1Physical Size = 1202Headers Size = 172 Date Time Attr Size Compressed Name------------------- ----- ------------ ------------ ------------------------2008-10-02 15:48:01 ....A 27216 1030 file1.txt2008-10-02 15:47:45 ....A 3888 file2.txt------------------- ----- ------------ ------------ ------------------------ 31104 1030 2 files, 0 folders
Warning:Don't confuse the two. This one is used for diagnostics. We usually want the hyphen "-t."
7z t archive.zip *.doc -r7z: use this executablet: test the specified archivearchive.zip: the archive you want to test*.doc: test all these files in the archive-r: recurse all child directories
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.
7z u archive.zip *.doc7z: executable nameu: update commandarchive.zip: archive you want to update files in*.doc: only update these files (Word documents)
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 -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". This may be enabled by default.
7z x archive.zip7z: executable namex: use the extract commandarchive.zip: the archive you want to extract all the files from
Type switches Switch: -t7z Format: 7ZExample filename: archive.7z (default option) Switch: -tgzip Format: GZIPExample filename: archive.gzip, archive.gz Switch: -tzip Format: ZIPExample filename: archive.zip (compatible) Switch: -tbzip2 Format: BZIP2Example filename: archive.bzip2 Switch: -ttar Format: TARExample filename: tarball.tar (UNIX and Linux) Switch: -tiso Format: ISOExample filename: image.iso (may not be supported) Switch: -tudf Format: UDFExample filename: disk.udf
7z a -tiso archive.iso7z a -tudf archive.udf7z: executable namea: add to archive-tiso or -tudf: format of archive to createarchive.iso or archive.udf: name of archive to create
Switch -ms=on:Enable solid mode. This is the default so you won't often need to specify it.
Switch -ms=off:Disable solid mode. Useful when you need to update individual files. Will reduce compression ratios normally.
PPMd switch -mmem=24b, -mmem=24k, -mmem=24m:These control the amount of memory you use. They are useful and higher is normally better.
PPMd switch -mo=2, -mo=32:These specify the model order in PPMd. They are not normally useful.
Tip:You should use PPMd when you have a large corpus (body) of text. This could include HTML. It can improve ratios by around 30%.
7z a -tzip archive.zip *.jpg -mx07z: name of executablea: add to archive command-tzip: specify a ZIP archive (useful for compatibility)archive.zip: destination archive*.jpg: only add jpg files to archive-mx0: don't compress, just copy useful for already-compressed files
7z a -t7z archive.7z *.exe *.dll -ms -mmt7z: name of executablea: archive command specified-t7z: use 7z file type (less compatible and smaller results)archive.7z: destination archive file*.exe: include all *.exe files in directory in new archive*.dll: include all *.dll files in new archive-ms: create solid archive (default)-mmt: multithread the operation (faster)
Tip:The command is useful because you will normally want to only compress text files with PPMd.
PPMd Compression7z a -t7z archive.7z *.txt -m0=PPMd7z: executable name/patha: add command specified-t7z: use the 7z format (needed for PPMd)archive.7z: destination archive file*.txt: select all text files-mo=PPMd: compress with this algorithm
7z x archive.zip -oC:\Doc7z: executable namex: extract archive with paths intactarchive.zip: archive to extract files from-oC:\Doc: extract all files to the Doc folder on the C: drive
7za a pw.7z *.txt -pSECRET7za: name and path of 7-Zip executablea: add to archivepw.7z: name of destination archive*.txt: add all text files to destination archive-pSECRET: specify the password "SECRET"
Header encryption:Add -mhe to encrypt headers. The password command will automatically deal with encrypted headers.
Tip:Remember, encrypted headers will hide the names of the files in your archive.
C:\Users\Sam>7za x pw.7z7-Zip (A) 4.60 beta Copyright (c) 1999-2008 Igor Pavlov 2008-08-19Processing archive: pw.7zEnter password:
Switch -ssc:Specify case-sensitive mode. The default is -ssc- on Windows (insensitive). The default is -scc on Linux (sensitive).
Switch -ssw:Compress locked files. You can try this if you have problems opening files.
Switch -w:Set working directory. You can use this when you want to specify temp folders.
7za.exe a archive.7z Z*.* -ssc7za.exe: 7-Zip command-line executable path and namea: archive commandarchive.7z: add files to this target archiveZ*.*: select only files whose first letter is a capital Z
Also:You can specify sequential volumes with the "v" switch on the 7za.exe command line.
Switch -aoa:This switch overwrites all destination files. Use it when the new versions are preferred.
Switch -aos:Skip over existing files without overwriting. Use this for files where the earliest version is most important.
Switch -aou:Avoid name collisions. New files extracted will have a number appending to their names. You will have to deal with them later.
Switch -aot:Rename existing files. This will not rename the new files, just the old ones already there.
Examples:7z x test.zip -aoa7z: use the 7-zip executablex: use the extract commandtest.zip: extract files from this archive-aoa: overwrite all existing files
Example:For example, *.txt means all text files. You can use the wildcard anywhere.
7z a -tzip archive.zip subdir7z: use executablea: add to archive-tzip: use zip compressionarchive.zip: create this archivesubdir\: source directory
Tip:Change the archive not to be solid if you want to update it. Search this page for "solid".
7z e archive.zip -oC:\soft *.cpp -r7z: executablee: use extract commandarchive.zip: source archive you want to extract from-oC:\soft: the destination folder (-o is the switch and C:\soft is the argument)*.cpp: only extract cpp files (C++)-r: traverse all subdirectories
So:If you want to exclude "file1.txt", use the switch "-x!file1.txt". Please include the hyphen and exclamation.
Note:Use -aos if your files don't change over time and overwriting would just be a waste.
Filters:You can change compression filters, which change behaviors on executable files such as *.exe and *.dll.
And:You can enable header compression and encryption (-mhc=on and -mhe=on). Header compression is by default enabled.
联系客服