7-Zip for Windows creates smaller zip archives than WinZip, so presumably P7zip can create smaller zip archives than Zip in Linux. So how do I create zip files using P7zip in Linux?
-
You're in linux Historically P7Zip is better used as a GUI in linux than an actual tool. As such, P7Zip uses the native tool's on linux to create an archive. I urge you to read the Tar Man Page– eyoung100May 7, 2014 at 17:49
-
Welcome to Stack Exchange. This is a questions and answers site, not a discussion forum. Please ask separate questions separately — since nobody's answered different parts yet (fortunately), I edited out your second question, you're welcome to post it separately.– Gilles 'SO- stop being evil'May 7, 2014 at 23:10
-
@ECarterYoung P7zip doesn't call any external tool. I don't know where you get that it's a GUI: P7zip is a command line tool (there are third-party GUI frontends for it).– Gilles 'SO- stop being evil'May 8, 2014 at 0:35
1 Answer
Experimentally, 7z
does compress a little better than zip
. I don't know how it compares with Winzip.
$ zip -q zip.zip /bin/{bash,cp,ls}
$ zip -q -9 zip9.zip /bin/{bash,cp,ls}
$ 7z a 7z.zip /bin/{bash,cp,ls} >/dev/null
$ 7z -mx=9 a 7z9.zip /bin/{bash,cp,ls} >/dev/null
$ du -ab *.zip | sort -n
550617 7z9.zip
559890 7z.zip
576161 zip9.zip
578382 zip.zip
The numeric option (-9
for zip
, -mx=9
for 7z
) tells the tool to spend more time to achieve a better compression ratio (it's a scale from 0 to 9).
You'll get better compression by using 7z format instead of zip format. The downside is that you need P7zip for decompression, Winzip can't handle it.
$ 7z -mx=9 a 7z9.7z /bin/{bash,cp,ls} >/dev/null
$ 7z a 7z.7z /bin/{bash,cp,ls} >/dev/null
$ du -ab *.7z | sort -n
471964 7z9.7z
472415 7z.7z
Install P7zip from your distribution's packages; if you have some weirdly incomplete distribution that doesn't include it, get it from upstream. There are three executables (sometimes package separately): 7zr
only handles 7z archives, 7z
handles many common archive formats (including zip), and 7za
supports additional plugins (useful for rar, which requires non-free code that isn't linked into 7z itself). You can use the option -m
to select the archive format, but usually this isn't required since the tool selects the format from the file name.