0% found this document useful (0 votes)
193 views

7 Zip Command Line Examples

This document provides examples of common 7-Zip command line commands and switches. It covers commands like a, d, e, l, t, u, and x as well as switches like -m, -t, and -r. Examples are given for each to demonstrate their usage.

Uploaded by

Mushtaque Asghar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
193 views

7 Zip Command Line Examples

This document provides examples of common 7-Zip command line commands and switches. It covers commands like a, d, e, l, t, u, and x as well as switches like -m, -t, and -r. Examples are given for each to demonstrate their usage.

Uploaded by

Mushtaque Asghar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

7/26/2016 7ZipCommandLineExamples

Go C#:.NET: .NET Array


Compression
Dictionary List String 2D Async Console DataTable
Dates DateTime Enum File For Foreach Format
IEnumerable If IndexOf Lambda LINQ Optimize Parse
Path Process Property Random Regex Replace Sort
Split Static Substring Switch Tuple While
7Zip.The7za.exeprogramisusedtocompress,extract
andupdatefilesthroughthecommandline.Itprovides
superiorcompression.Itisagreatprogram.

7Zipisopensource.Thismakesiteasytoobtainanduse.
Thisdocumentcoverssomecommoncommandlines(focused
onWindows,butapplicabletoanyOSlikeLinuxorMacOS
X).
Start.Downloadthe7Zipcommandlineexecutable:7za.exe.This
istheexeyouwillusetoruncommandsonarchives.Pleasegoto7
zip.organdgetthecommandlineversion.

Tip:
Forconvenienceandsoyoudon'tneedtochangeenvironment
paths,putthe7za.exefileinyouruserdirectory.

Next:
OpentheWindowsconsoleandtestthe7za.exeprogramoutwithafew
commands.Typeintheexename7zaandthiswilldisplay.

Grammar:
Weseethegrammarweneedtousewith7za.exe.The"command"isthemain
verb.

Switches:
Thenyouspecifyoptionalswitches,thearchivename(sourceordestination)and
files.Myuserdirectoryis"C:\Users\Sam\".

7Zipdefaultoutput

Zip A . 0betaCopyright c 00 IgorPavlov


00 0

http://www.dotnetperls.com/7zipexamples 1/16
7/26/2016 7ZipCommandLineExamples

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

Commanda.Youcanusethe"a"commandwith
thesinglelettera.Thiscommandstandsfor
"archive"or"add."Useittoputfilesinanarchive.

Arguments:
Youhavetospecifythedestinationarchive,and
thesourcefiles(inthatorder).

Note:
Onthetestsystem,"C:\Users\Sam"containstwo
files(file1.txtandfile2.txt).Thecommandputsthosetwofilesinanarchive.

Tip:
Toopenyourarchive,rightclickonitandselect7Zip>Openarchive.The
screenshotshowsthefilescompressedinfiles.7z.

Examplecommandline

C:\Users\Sam> zaat zfiles. z*.txt

Zip A . 0betaCopyright c 00 IgorPavlov 00 0


Scanning

Creatingarchivefiles. z

Compressingfile .txt
Compressingfile .txt

EverythingisOk

C:\Users\Sam>

Commandd.Weusethe"d"commandin7Zipcommandlines.
Thisstandsfordelete.Itallowsyoutoremoveacertainfile(orset
http://www.dotnetperls.com/7zipexamples 2/16
7/26/2016 7ZipCommandLineExamples

offiles)frominsideanarchive.

Note:
Youwillneedthisifyouusehugearchivesandneedtosavetime.
Thisisfromthemanual.

Tip:
Youcanalsoremoveasinglefilefromanarchivewith"d".Thisismoreuseful
whenyoudonothaveasolidarchive.

Exampledcommandline

zdarchive.zip*.bakr

z:useexecutable
d:deletefiles
archive.zip:deletefromthisarchive
*.bak:onlymatchbakfiles
r:traverseallsubdirectories

Commande.The"e"standsforextract,anditmeanstounzipor
expandanarchive.Youmustspecifythesourcearchivealways,and
mayalsospecifyadestination.

Info:
The"e"commandextractseverythingtoaspecifieddirectory.
Anothercommand"x"canpreservedirectorystructuresinarchives.

Overwriteprompts:
7Zipwillalwayspromptyouifthereisafileitneedstooverwritetoextractthe
newfile.

However:
Thiscanbeproblematicifyouarescriptingorembedding7za.exe.Inthatcase,
seetheyswitch.

Exampleecommandline

zearchive.zip

z:executable
e:useextractcommand
archive.zip:sourcearchiveyouwanttoexpand
http://www.dotnetperls.com/7zipexamples 3/16
7/26/2016 7ZipCommandLineExamples

Commandl.ThelowercaseLisusedtolistthecontentsof
archives.Youprobablywillnotneedtouseitoften.I
thoughtIwouldtestitandshowanexample.

Next:
Thisshowsthelistingofasolidarchive.Theoriginalsare27216bytesand3888
bytes.Theycompressdownto1030bytes.

Examplelcommandline

C:\Users\Sam> zalfiles. z

Zip A . 0betaCopyright c 00 IgorPavlov 00 0

Listingarchive:files. z

Method=LZMA
Solid=+
Blocks=
PhysicalSize= 0
HeadersSize=

DateTimeAttrSizeCompressedName

00 00 : :0 ....A 0 0file .txt


00 00 : : ....A file .txt

0 0 0 files,0folders

Commandt.Hereweusethe"t"commandinthe7zprogram.This
commandallowsyoutotesttheintegrityofarchives.Itstandsfor
'test'andismuchlessusefulthanthe"t"switch.

Warning:
Don'tconfusethetwo.Thisoneisusedfordiagnostics.Weusually
wantthehyphen"t."

Exampletcommandline

ztarchive.zip*.docr

z:usethisexecutable

http://www.dotnetperls.com/7zipexamples 4/16
7/26/2016 7ZipCommandLineExamples

t:testthespecifiedarchive
archive.zip:thearchiveyouwanttotest
*.doc:testallthesefilesinthearchive
r:recurseallchilddirectories

Commandu.Thisstandsforupdate.Thiscommandreplacesold
filesinyourarchivewithnewerfiles.Thispreventsneedingto
decompressandrecompresstheentirearchive.

Warning:
The"u"commanddoesn'tworkwithsolidarchives.Asolidarchiveis
onewhereallthefilesarecompressedtogether.

So:
Youcannotupdatespecificfilesinsolidarchiveswiththe"u"command.Solid
archivesarelimited.

Exampleucommandline

zuarchive.zip*.doc

z:executablename
u:updatecommand
archive.zip:archiveyouwanttoupdatefilesin
*.doc:onlyupdatethesefiles Worddocuments

Switchm.Wecanchangetheoptimizationsettingsin7
Ziponthecommandline.Thisisthemostimportantand
usefuloptionyoucanuse.

Tip:
Itspecifiesthemethodofcompression.HereIwillshowabunchofoptions,and
alsosomeexamples.

Compressionlevels:

Switchmx0:Don'tcompressatall.
Thisiscalled"copymode."

Switchmx :Lowcompression.
Thisiscalled"fastest"mode.

http://www.dotnetperls.com/7zipexamples 5/16
7/26/2016 7ZipCommandLineExamples

Switchmx :Fastcompressionmode.
Willautomaticallysetvariousparameters.

Switchmx :Sameasabove,but"normal."

Switchmx :Thismeans"maximum"compression.

Switchmx :Thismeans"ultra"compression.
Youprobablywanttousethis.

Switchm,advanced.Hereareadvancedcompressionmethod
(m)switches.Thefirstthreeareusuallyoflimiteduse.My
experienceisthatmanualoptimizationsdoesn'tproducebig
benefits.

Switchmfb:
Specifiesnumberoffastbytes.Sometimeshelpswith"sparse"files.Don't
bother.

Switchmpass:
Numberofpassesfordeflatecompression.Don'tbotherwiththis.Automatically
setwithlevels.

Switchmd:
Thisspecifiesdictionarysize.Itisautomaticallyset,sodon'tbother.

Switchmmt:
Enablemultithreading.Useifyouhavequadcoreandahugearchive.Specify
"on"or"off".Thismaybeenabledbydefault.

Commandx.Thiscommandislike"e"exceptitpreservesthefull
paths.Ifyouhaveanelaborateorimportantdirectorystructure,use
thisoption.Thiswouldbemostusefulforbackups.

Examplexcommandline

zxarchive.zip

z:executablename
x:usetheextractcommand
archive.zip:thearchiveyouwanttoextractallthefilesfrom

http://www.dotnetperls.com/7zipexamples 6/16
7/26/2016 7ZipCommandLineExamples

Switchttype.HereIshowhowtospecifythearchivetype.Note
thatyoucanspecifyanyfilenameyouwantforanytype.Butsome
extensionsarerecommendedtheyarestandard.

Typeswitches

Switch:t z
Format: Z
Examplefilename:archive. z defaultoption

Switch:tgzip
Format:GZIP
Examplefilename:archive.gzip,archive.gz

Switch:tzip
Format:ZIP
Examplefilename:archive.zip compatible

Switch:tbzip
Format:BZIP
Examplefilename:archive.bzip

Switch:ttar
Format:TAR
Examplefilename:tarball.tar UNIXandLinux

Switch:tiso
Format:ISO
Examplefilename:image.iso maynotbesupported

Switch:tudf
Format:UDF
Examplefilename:disk.udf

Typeswitchexamples.The7Zipmanualshowsthe
tisoandtudfswitches.Thesearenotthemostcommon.
Almostalloftheexamplesinthisdocumentuset
switches.

Exampleacommandlines

zatisoarchive.iso
zatudfarchive.udf

z:executablename
http://www.dotnetperls.com/7zipexamples 7/16
7/26/2016 7ZipCommandLineExamples

a:addtoarchive
tisoortudf:formatofarchivetocreate
archive.isoorarchive.udf:nameofarchivetocreate

Solidarchives.7zistheonlyfileformatin7Zipthatyou
canspecifywhetherthearchiveissolidornot.Solidmakesit
impossibletousethe"u"commandtoupdateindividualfiles.

Switchms=on:
Enablesolidmode.Thisisthedefaultsoyouwon'toftenneed
tospecifyit.

Switchms=off:
Disablesolidmode.Usefulwhenyouneedtoupdateindividualfiles.Willreduce
compressionratiosnormally.

7zarchives.Somethingsyoucanchangearedictionarysizes,
FastBytesvalues,MatchFindervalues,andfilters.Normallyyou
don'tneedtodealwiththese.

PPMd.Withthe7zformat,youcanspecifythealgorithm.PPMdis
goodforcompressingplaintextfiles.ItisidealforWorddocuments.
PPMddoesnotperformaswellonbinarydata.

PPMdswitchmmem=24b,mmem=24k,mmem=24m:
Thesecontroltheamountofmemoryyouuse.Theyareusefuland
higherisnormallybetter.

PPMdswitchmo=2,mo=32:
ThesespecifythemodelorderinPPMd.Theyarenotnormallyuseful.

Tip:
YoushouldusePPMdwhenyouhavealargecorpus(body)oftext.Thiscould
includeHTML.Itcanimproveratiosbyaround30%.

Examplecommands.HereIshowtheexample
compressioncommandsfromthe7Zipmanual.I

http://www.dotnetperls.com/7zipexamples 8/16
7/26/2016 7ZipCommandLineExamples

demonstratedsimpleonesatthestartofthis
document.Thesearemorecomplex.

Exampleacommandline

zatziparchive.zip*.jpgmx0

z:nameofexecutable
a:addtoarchivecommand
tzip:specifyaZIParchive usefulforcompatibility
archive.zip:destinationarchive
*.jpg:onlyaddjpgfilestoarchive
mx0:don'tcompress,justcopy
usefulforalreadycompressedfiles

Exampleof7zformat.Thisnextcommandlineshows
howtocreateasolid7zarchiveofprogramfiles
(executables).Itusesmultithreadingmode,whichmeans
itwillbefast.

Examplemscommandline

zat zarchive. z*.exe*.dllmsmmt

z:nameofexecutable
a:archivecommandspecified
t z:use zfiletype lesscompatibleandsmallerresults
archive. z:destinationarchivefile
*.exe:includeall*.exefilesindirectoryinnewarchive
*.dll:includeall*.dllfilesinnewarchive
ms:createsolidarchive default
mmt:multithreadtheoperation faster

CreatePPMdarchive.PPMdisanextraordinary
algorithmforcompressingtext.HereIshowacommand
inthe7Zipmanualthatcompressesallthetextfilesin
theworkingdirectory.

Tip:
Thecommandisusefulbecauseyouwillnormallywanttocompressonlytext
fileswithPPMd.

http://www.dotnetperls.com/7zipexamples 9/16
7/26/2016 7ZipCommandLineExamples

PPMdCompression

ExamplePPMdcommandline

zat zarchive. z*.txtm0=PPMd

z:executablename/path
a:addcommandspecified
t z:usethe zformat neededforPPMd
archive. z:destinationarchivefile
*.txt:selectalltextfiles
mo=PPMd:compresswiththisalgorithm

Switcho.Sometimesyoudonotwanttoextracttothecurrent
directory.Thisiswhereocancomeinhandy.Usethistosetthe
destinationdirectory.

Exampleocommandline

zxarchive.zipoC:\Doc

z:executablename
x:extractarchivewithpathsintact
archive.zip:archivetoextractfilesfrom
oC:\Doc:extractallfilestotheDocfolderontheC:drive

Switchp.Wecanusethe"p"switch,whichreferstotheword
"password".Thisisreallyhelpfulwhensecurityandencryptionis
involved.Youcanspecifyapasswordonthecommandline.

Examplepcommandline

zaapw. z*.txtpSECRET

za:nameandpathof Zipexecutable
a:addtoarchive
pw. z:nameofdestinationarchive
*.txt:addalltextfilestodestinationarchive
pSECRET:specifythepassword"SECRET"

Openingpasswordprotectedarchives.Thisnextconsole
outputshowswhathappenswhenyoutrytoopenthe

http://www.dotnetperls.com/7zipexamples 10/16
7/26/2016 7ZipCommandLineExamples

passwordprotectedarchive.ThepasswordhereisSECRET.I
amsoclever.

Headerencryption:
Addmhetoencryptheaders.Thepasswordcommandwillautomaticallydeal
withencryptedheaders.

Tip:
Remember,encryptedheaderswillhidethenamesofthefilesinyourarchive.

Examplexcommandline

C:\Users\Sam> zaxpw. z

Zip A . 0betaCopyright c 00 IgorPavlov 00 0

Processingarchive:pw. z

Enterpassword:

Moreswitches.Herewetakeacloserlookatmore
switchesthatareoflimiteduse.Theyaresometimes
usefultoknow.Usuallyyoucandobetterjustbyusing
thedefaults.

Switchssc:
Specifycasesensitivemode.ThedefaultisssconWindows(insensitive).The
defaultisscconLinux(sensitive).

Switchssw:
Compresslockedfiles.Youcantrythisifyouhaveproblemsopeningfiles.

Switchw:
Setworkingdirectory.Youcanusethiswhenyouwanttospecifytempfolders.

Casesensitive.Wecanusecaseinsensitivefilenames.
Forcrossplatformstuff,thecasesensitiveoptionisuseful.
Iwillshowmyownexampleherewithsomeexplanation.

Examplessccommandline

http://www.dotnetperls.com/7zipexamples 11/16
7/26/2016 7ZipCommandLineExamples

za.exeaarchive. zZ*.*ssc

za.exe: Zipcommandlineexecutablepathandname
a:archivecommand
archive. z:addfilestothistargetarchive
Z*.*:selectonlyfileswhosefirstletterisacapitalZ
ssc:caseinsensitivematching

Switchv.Indatacompression,avolumeisasegmentofa
datasetthatisacertainnumberofbyteslong.Thevolume
switchspecifiestheexactsizeinbytes,kilobytesor
megabytes.

Also:
Youcanspecifysequentialvolumeswiththe"v"switchonthe7za.execommand
line.

Switchao.The"ao"switchallowsyoutospecifywhetheryou
wanttooverwriteoldfiles.Becarefulyoucannotrestorean
overwrittenfilenormally.Thisswitchtakesanotherargument.

Switchaoa:
Thisswitchoverwritesalldestinationfiles.Useitwhenthenewversionsare
preferred.

Switchaos:
Skipoverexistingfileswithoutoverwriting.Usethisforfileswheretheearliest
versionismostimportant.

Switchaou:
Avoidnamecollisions.Newfilesextractedwillhaveanumberappendingtotheir
names.Youwillhavetodealwiththemlater.

Switchaot:
Renameexistingfiles.Thiswillnotrenamethenewfiles,justtheoldones
alreadythere.

Examples:

http://www.dotnetperls.com/7zipexamples 12/16
7/26/2016 7ZipCommandLineExamples

zxtest.zipaoa

z:usethe zipexecutable
x:usetheextractcommand
test.zip:extractfilesfromthisarchive
aoa:overwriteallexistingfiles

Multiplefiles.Toaddmanyfilestoonearchive,pleaseuse
the"a"commandandthewildcard*symbol.Specifythename
ofthedestinationarchivefileandthesourcefilesafterwards.

HowdoIaddmanyfileswithaspecificextension?Usethe"a"
commandandthewildcard*symbol,butspecifytheextensionafter
thewildcard.

Example:
Forexample,*.txtmeansalltextfiles.Youcanusethewildcard
anywhere.

HowcanIaddmanyfilesfromanentiresubdirectory?Specify
justthedirectoryname.Youdonotneedtouseawildcard.This
commandspecifiesanentiredirectorycalled"subdir".

Examplesubdirectorycommandline

zatziparchive.zipsubdir\

z:useexecutable
a:addtoarchive
tzip:usezipcompression
archive.zip:createthisarchive
subdir\:sourcedirectory

HowdoIuseBZip2?YoucanuseBZip2byspecifying
the"tbzip2"switch.Thiscanbecombinedwithany
compressionlevel.Themodesin7Zipautomaticallyuse
manydifferentsettings.
HowdoIuse7zformat?Specifythe"t7z"switchfortype.Or
youcansimplyomitthetypeswitchandthatwilldefaultto7z.This
http://www.dotnetperls.com/7zipexamples 13/16
7/26/2016 7ZipCommandLineExamples

formatoffersthegreatestcompressionratios.

Prompts.Youcanstop7Zipfromdisplayingprompts.Please
usetheyswitch.Thiswillassumeayesanswertoall
prompts.Usethisonlywhenyouareconfident.

Whycan'tIupdatemyarchive?Itisprobablyasolidarchive.7z
archivesarebydefaultsolidarchivesallthefilesarecompressed
together.

Tip:
Changethearchivenottobesolidifyouwanttoupdateit.Search
thispagefor"solid".

CanIspecifytheoutputdirectory?Usethe"e"commandand
combineitwiththeoswitch.Thesyntaxwithoisabitfunny.This
istheexamplefromthe7Ziphelpfile.

Exampleoutputdirectorycommandline

zearchive.zipoC:\soft*.cppr

z:executable
e:useextractcommand
archive.zip:sourcearchiveyouwanttoextractfrom
oC:\soft:thedestinationfolder
oistheswitchandC:\softistheargument
*.cpp:onlyextractcppfiles C++
r:traverseallsubdirectories

HowcanIseewhat'sinsideanarchive?Usethe"l"
command.Youmightwanttouse"l"inautilitythatyourun
fromacommandlinetomakesureyourbatcharchiving
properlyworks.
HowcanIexcludecertainfiles?Sometimesyouwantto
manuallyexcludecertainfiles.Usethexswitch,followed
immediatelywithanexclamationmarkandthenthefilename.
http://www.dotnetperls.com/7zipexamples 14/16
7/26/2016 7ZipCommandLineExamples

So:
Ifyouwanttoexclude"file1.txt",usetheswitch"x!file1.txt".
Pleaseincludethehyphenandexclamation.

HowcanIreplacefiles?Byusingtheaoswitch,
describedabove.Thereareotheroptions,anditisusuallya
betterideatouseoneoftherenamingoptions(aouor
aot).

CanIignoreextractingfilesalreadyondisk?Yesspecifythe
aosoption,whichmeans"skipoverwritingfiles."Thiswillcause
7za.exetonotcopythenewerfilesoutofthearchive.

Note:
Useaosifyourfilesdon'tchangeovertimeandoverwritingwould
justbeawaste.

Embed.Youcanembed7ZipinaWindows.NETprogram.
Thisyieldsthesamegreatcompressionbutinyourown
GUI.Thelinkshowssomecompressionratios.

7ZipExecutable

Internalsettings.Youcanchangeinternalsettings.Youdonot
needtodothisnormally.Irecommendjustusingthemx=0(and
3,5,7,9)settings.Anindepthstudywouldbefascinating.

Filters:
Youcanchangecompressionfilters,whichchangebehaviorson
executablefilessuchas*.exeand*.dll.

And:
Youcanenableheadercompressionandencryption(mhc=onandmhe=on).
Headercompressionisbydefaultenabled.

http://www.dotnetperls.com/7zipexamples 15/16
7/26/2016 7ZipCommandLineExamples

Zopfli.Ifyouarereadingthispage,youprobablywanteven
bettercompression.IhavefoundthatZopflicancreategzip
archivesafewbytessmallerthan7Zipcan.Itisslowtorun.

Zopfli:github.com

AdvanceCOMP.YoucanuseAdvanceCOMPtoimprove
compressionratios.Theimprovementisoftensmall,lessthan
1%.AdvanceCOMPhasmoreoptionsandismorefine
grained.

AdvanceCOMP:sourceforge.net

Areview.7Zipcanbeusedonthecommandline.We
creatednewarchives,addedtoexistingarchives,used
differentformats,andusedvariousstrengths(August
2015).

http://www.dotnetperls.com/7zipexamples 16/16

You might also like