7-Zip.` The 7za.exe program is used to compress, extract and update files through the command line. It provides superior compression. It is a great program.`7-Zip is open-source.` This makes it easy to obtain and use. This document covers some common command lines (focused on Windows, but applicable to any OS like Linux or Mac OS X).`Start.` Download the 7-Zip command line executable: 7za.exe. This is the exe you will use to run commands on archives. Please go to 7-zip.org and get the command line version. `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\".`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).`On the test system, "C:\Users\Sam" contains two files (file1.txt and file2.txt). The command puts those two files in an archive.`To open your archive, right click on it and select 7-Zip -> Open archive. The screenshot shows the files compressed in files.7z.`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. `You will need this if you use huge archives and need to save time. This is from the manual.`You can also remove a single file from an archive with "d". This is more useful when you do not have a solid archive.`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.`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.`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."`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.`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. `It specifies the method of compression. Here I will show a bunch of options, and also some examples.`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. `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 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. `Solid archives.` 7z is the only file format in 7-Zip that you can specify whether the archive is solid or not. Solid makes it impossible to use the "u" command to update individual files. `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.`7z archives.` Some things you can change are dictionary sizes, FastBytes values, MatchFinder values, and filters. Normally you don't need to deal with these.`PPMd.` With the 7z format, you can specify the algorithm. PPMd is good for compressing plain text files. It is ideal for Word documents. PPMd does not perform as well on binary data. `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.`You should use PPMd when you have a large corpus (body) of text. This could include HTML. It can improve ratios by around 30%.`Example commands.` Here I show the example compression commands from the 7-Zip manual. I demonstrated simple ones at the start of this document. These are more complex. `Example of 7z format.` This next command line shows how to create a solid 7z archive of program files (executables). It uses multithreading mode, which means it will be fast. `Create PPMd archive.` PPMd is an extraordinary algorithm for compressing text. Here I show a command in the 7-Zip manual that compresses all the text files in the working directory. `The command is useful because you will normally want to compress only text files with PPMd.`PPMd Compression `ppmd`Switch o.` Sometimes you do not want to extract to the current directory. This is where -o can come in handy. Use this to set the destination directory. `Switch p.` We can use the "-p" switch, which refers to the word "password". This is really helpful when security and encryption is involved. You can specify a password on the command line. `Opening password-protected archives.` This next console output shows what happens when you try to open the password-protected archive. The password here is SECRET. I am so clever. `Header encryption: `Add -mhe to encrypt headers. The password command will automatically deal with encrypted headers.`Remember, encrypted headers will hide the names of the files in your archive.`More switches.` Here we take a closer look at more switches that are of limited use. They are sometimes useful to know. Usually you can do better just by using the defaults. `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.`Case-sensitive.` We can use case-insensitive file names. For cross-platform stuff, the case-sensitive option is useful. I will show my own example here with some explanation. `Switch v.` In data compression, a volume is a segment of a data set that is a certain number of bytes long. The volume switch specifies the exact size in bytes, kilobytes or megabytes. `You can specify sequential volumes with the "v" switch on the 7za.exe command line.`Switch ao.` The "ao" switch allows you to specify whether you want to overwrite old files. Be careful—you cannot restore an overwritten file normally. This switch takes another argument. `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.`Multiple files.` To add many files to one archive, please use the "a" command and the wildcard * symbol. Specify the name of the destination archive file and the source files afterwards.`How do I add` many files with a specific extension? Use the "a" command and the wildcard * symbol, but specify the extension after the wildcard. `Example: `For example, *.txt means all text files. You can use the wildcard anywhere.`How can I add` many files from an entire subdirectory? Specify just the directory name. You do not need to use a wildcard. This command specifies an entire directory called "subdir". `How do I use BZip2?` You can use BZip2 by specifying the "-tbzip2" switch. This can be combined with any compression level. The modes in 7-Zip automatically use many different settings.`How do I use 7z format?` Specify the "-t7z" switch for type. Or you can simply omit the type switch and that will default to 7z. This format offers the greatest compression ratios.`Prompts.` You can stop 7-Zip from displaying prompts. Please use the -y switch. This will assume a yes answer to all prompts. Use this only when you are confident.`Why can't I update my archive?` It is probably a solid archive. 7z archives are by default solid archives—all the files are compressed together. `Change the archive not to be solid if you want to update it. Search this page for "solid".`Can I specify the output directory?` Use the "e" command and combine it with the -o switch. The syntax with -o is a bit funny. This is the example from the 7-Zip help file. `How can I see` what's inside an archive? Use the "l" command. You might want to use "l" in a utility that you run from a command line to make sure your batch archiving properly works.`How can I exclude` certain files? Sometimes you want to manually exclude certain files. Use the -x switch, followed immediately with an exclamation mark and then the filename. `So: `If you want to exclude "file1.txt", use the switch "-x!file1.txt". Please include the hyphen and exclamation.`How can I replace files?` By using the -ao switch, described above. There are other options, and it is usually a better idea to use one of the renaming options (-aou or -aot).`Can I ignore` extracting files already on disk? Yes—specify the -aos option, which means "skip overwriting files." This will cause 7za.exe to not copy the newer files out of the archive. `Use -aos if your files don't change over time and overwriting would just be a waste.`Embed.` You can embed 7-Zip in a Windows .NET program. This yields the same great compression but in your own GUI. The link shows some compression ratios. `7-Zip Executable `7-zip`Internal settings.` You can change internal settings. You do not need to do this normally. I recommend just using the mx=0 (and 3, 5, 7, 9) settings. An in-depth study would be fascinating. `Filters: `You can change compression filters, which change behaviors on executable files such as *.exe and *.dll.`You can enable header compression and encryption (-mhc=on and -mhe=on). Header compression is by default enabled.`Zopfli.` If you are reading this page, you probably want even better compression. I have found that Zopfli can create gzip archives a few bytes smaller than 7-Zip can. It is slow to run. `Zopfli: github.com `https://github.com/google/zopfli`AdvanceCOMP.` You can use AdvanceCOMP to improve compression ratios. The improvement is often small, less than 1%. AdvanceCOMP has more options and is more fine-grained. `AdvanceMAME: github.com `https://github.com/amadvance/advancemame/`A review.` 7-Zip can be used on the command line. We created new archives, added to existing archives, used different formats, and used various strengths (August 2015).

JKQ75:HnFFFjFogyyyyyFjpFjjFjHFFFFFVFFFj|j_j_FjwjwFVMppqpq_F|wFzjjFVjjFFVjFFj_FjHV7-Zip default outputQ 7-Zip (A) 4.60 beta Copyright (c) 1999-2008 Igor Pavlov J2008-08-19 Usage: Q7zaQ <command> [<Kes>...] <archive_name> J [<file_names>...] J [<@Kfiles...>]QEK command line 1Q QC:\Users\Sam>7za a -t7z files.7z *.txtQ 7-Zip (A) 4.60 beta Copyright (c) 1999-2008 Igor Pavlov 2008-08-19 Scanning Creating archive files.7z Compressing file1.txt Compressing file2.txt Everything is Ok C:\Users\Sam>QEK d command lineQ Q7z d archive.zip *.bak -rQ 7z:JJ use executable d:JJ delete files archive.zip: delete from this archive *.bak:J only match bak files -r:JJ traverse all subdirectoriesQEK e command lineQ Q7z e archive.zipQ 7z:JJ executable e:JJ use extract command archive.zip: source archive you wantKexpandQEK l command lineQ QC:\Users\Sam>7za l files.7zQ 7-Zip (A) 4.60 beta Copyright (c) 1999-2008 Igor Pavlov 2008-08-19 King archive: files.7z MKKLZMA SolidK+ BlocksK1 Physical SizeK1202 Headers SizeK172 DateJ TimeJAttrJJ Size Compressed Name ------------------- ----- ------------ ------------ ------------------------ 2008-10-02 15:48:01 ....AJJ27216JJ 1030 file1.txt 2008-10-02 15:47:45 ....AJJ 3888JJJ file2.txt ------------------- ----- ------------ ------------ ------------------------ JJJJJJJJ 31104JJ 1030 2 files, 0 foldersQEK t command lineQ Q7z t archive.zip *.doc -rQ 7z:JJ use this executable t:JJ test the specified archive archive.zip: the archive you wantKtest *.doc:J test all these filesKthe archive -r:JJ recurse all child directoriesQEK u command lineQ Q7z u archive.zip *.docQ 7z:JJ executable name u:JJ update command archive.zip: archive you wantKupdate files in *.doc:J only update these files (Word documents)QCompression levels:Q Switch -mx0: Don't compress at all. JJJ This is called "copy mode." Switch -mx1: Low compression. JJJ This is called "fastest" mode. Switch -mx3: Fast compression mode. JJJ Will automatically set various parameters. Switch -mx5: Same as above, but "normal." Switch -mx7: This means "maximum" compression. Switch -mx9: This means "ultra" compression. JJJ You probably wantKuse this.QEK x command lineQ Q7z x archive.zipQ 7z:JJ executable name x:JJ use the extract command archive.zip: the archive you wantKextract all the files fromQType KesQ JJ Switch: -t7z JJ Format: 7Z EK filename: archive.7z (default option) JJ Switch: -tgzip JJ Format: GZIP EK filename: archive.gzip, archive.gz JJ Switch: -tzip JJ Format: ZIP EK filename: archive.zip (compatible) JJ Switch: -tbzip2 JJ Format: BZIP2 EK filename: archive.bzip2 JJ Switch: -ttar JJ Format: TAR EK filename: tarball.tar (UNIXKLinux) JJ Switch: -tiso JJ Format: ISO EK filename: image.iso (may not be supported) JJ Switch: -tudf JJ Format: UDF EK filename: disk.udfQEK a command linesQ Q7z a -tiso archive.iso 7z a -tudf archive.udfQ 7z:JJJJJJ executable name a:JJJJJJ addKarchive -tiso or -tudf:JJJ Kmat of archiveKcK archive.iso or archive.udf: name of archiveKcKQEK a command line 2Q Q7z a -tzip archive.zip *.jpg -mx0Q 7z:JJ name of executable a:JJ addKarchive command -tzip:J specify a ZIP archive (useful Kcompatibility) archive.zip: destination archive *.jpg:J only add jpg filesKarchive -mx0:JJdon't compress, just copy JJJ useful Kalready-compressed filesQEK ms command lineQ Q7z a -t7z archive.7z *.exe *.dll -ms -mmtQ 7z:JJ name of executable a:JJ archive command specified -t7z:J use 7z file type (less compatibleKsmaller Ks) archive.7z: destination archive file *.exe:J include all *.exe filesKdirectoryKKarchive *.dll:J include all *.dll filesKKarchive -ms:JJcK solid archive (default) -mmt:J multithread the operation (faster)QEK PPMd command lineQ Q7z a -t7z archive.7z *.txt -m0=PPMdQ 7z:JJ executable name/path a:JJ add command specified -t7z:J use the 7z Kmat (needed KPPMd) archive.7z: destination archive file *.txt:J select all text files -mo=PPMd: compress with this algorithmQEK o command lineQ Q7z x archive.zip -oC:\DocQ 7z:JJ executable name x:JJ extract archive with paths Kact archive.zip: archiveKextract files from -oC:\Doc:Jextract all filesKthe Doc folder on the C: driveQEK p command lineQ Q7za a pw.7z *.txt -pSECRETQ 7za:J nameKpath of 7-Zip executable a:JJaddKarchive pw.7z:Jname of destination archive *.txt:Jadd all text filesKdestination archive -pSECRET: specify the password "SECRET"QEK x command line 2Q QC:\Users\Sam>7za x pw.7zQ 7-Zip (A) 4.60 beta Copyright (c) 1999-2008 Igor Pavlov 2008-08-19 Processing archive: pw.7z Enter password:QEK ssc command lineQ Q7za.exe a archive.7z Z*.* -sscQ 7za.exe:J7-Zip command-line executable pathKname a:JJ archive command archive.7z: add filesKthis target archive Z*.*:J select only files whose first letter is a capital Z -ssc:J case-insensitive matchingQEKs:Q Q7z x test.zip -aoaQ 7z:J use the 7-zip executable x:JJuse the extract command test.zip: extract files from this archive -aoa:J overwrite all existing filesQEK subdirectory command lineQ Q7z a -tzip archive.zip subdir\Q 7z:JJ use executable a:JJ addKarchive -tzip:J use zip compression archive.zip: cK this archive subdir\:J source directoryQEK output directory command lineQ Q7z e archive.zip -oC:\soft *.cpp -rQ 7z:JJ executable e:JJ use extract command archive.zip: source archive you wantKextract from -oC:\soft: the destination folder JJJ (-o is the KKC:\soft is the argument) *.cpp:J only extract cpp files (C++) -r:JJ traverse all subdirectoriesQ