Create Zip files on the command line very easy and flexible. Include/exclude sub folders and file names, or zip just files changed today, with the free Open Source tool Swiss File Knife for Windows, Mac OS and Linux.
sfk zip out[.zip] [opt] mydir [file1 file2 ...]sfk zip out[.zip] [opt] -dir mydir -file file1 file2
add files and folders to a .zip file.
About filename encoding
if filenames contain special chars like umlauts
or accents the following applies:
- under windows, sfk zip stores filenames
1. in the OEM codepage of your system,
to support old extraction tools.
2. and as UTF-8, in the zip format 0x7075 extension
which will be used by up-to-date programs.
- under linux, sfk stores only one name, which is
marked as UTF-8, if such encoding is detected.
on any other encoding, like accent chars on old file
systems, sfk zip stores characters as is, and later
extraction may produce wrong names.
- UTF-8 name extensions are supported only by up-to-
date zip extraction tools, like 7zip, Windows 10
File Explorer, or sfk unzip.
- names with accent chars exchanged between Mac and
Non-Mac systems may look wrong due to Decomposed
Unicode used in Mac OS/X.
if you extract files at the receiver, then open
windows explorer and see unexpected filename
characters, this means the receiver's unzip tool
is old and does not understand UTF-8 extensions.
- if you just see wrong accent characters
it means the receiver system uses a different
OEM codepage then the sender (sfk sysinfo).
- if you see #Uxxxx it means filenames contain
complex unicode chars, like asian or cyrillic.
you can google for U+xxxx to see what character
is actually meant.
No update of existing content
if the output zip file already exists
then only new files which are not already
contained can be added. sfk cannot update
contents and times within existing zip files.
sfk zip may fail to compare added filenames
to existing names in a zip if name encodings
are mixed or unclear, esp. on linux/mac.
64 bit zip file support
if contents are larger then 2 gb, sfk zip
will create a 64 bit zip file automatically.
not every unzip tool may be able to read this.
SFK XE cannot read zip file contents over 2 gb.
-nosub do not include sub folders.
-force overwrite existing zip file.
-zipext add .zip to output filename even
if it already has an extension.
-asdir x create a new folder x within the zip
and add all files into that folder.
cannot add to an existing folder.
-rel[names] strip top level folder from
filenames within the zip.
-big show a summary of largest files.
-big=n show a summary of n largest files.
-old=n show a summary of n oldest files.
-nosum show no summary.
-text include only ascii text files
but no binary files.
-nometa do not add the os/code comment,
or set SFK_CONFIG=nozipmeta
-setexec mask1 mask2 !mask3 ...
mark files as executable with
linux/mac operating systems.
must be followed by -dir ...
-offtime store file times which are
one hour off, depending on DST.
for details see: sfk help offtime
output filename rendering
if output filename does not contain '.'
then '.zip' is added. use -zipext to add
whenever if it does not contain .zip
sfk zip supports text output chaining,
to pass filenames for filtered display.
see alsosfk zipuni use just UTF-8 filenames,
to support old linux tools.
sfk unzip extract a zip file.
sfk zipto zip files selected by a
sfk zip is very flexible and easy to use,
but if you need special features like
direct zip file updating you may consider
further zipping tools. find an overview on:
stahlworks.com/zipexamplessfk zip out mydir !.bak
add all contents of mydir into out.zip,
except for .bak files, using the short
file selection syntax.
sfk zip out -dir foo bar -file !.bak
add all contents of folder foo and folder
bar into out.zip, except for .bak files,
using the long file selection syntax.
sfk zip out -dir mydir -subdir !save !\tmp-file !.bak !old
add all of mydir into out.zip, except for
sub folders having 'save' in their name or
starting with 'tmp', and except for files
with .bak extension or 'old' in their name.
sfk select mydir .png +zipto out
add all .png images of mydir to out.zip.
sfk zip out mydir .png
same as above, in one step.
sfk zip out -since 3d mydir
add files changed in the last three days.
sfk list -late=5 mydir +zipto out -force
write the 5 newest files to out.zip,
overwriting an existing out.zip
sfk zip out -setexec /conf/ .sh -dir mydir
zip mydir, mark files named exactly conf,
or being in a folder conf, or having .sh
in their name as executable on linux.
sfk unzip -todir tmpdoc in.odtsfk zip -rel out.odt tmpdoc
extract an openoffice writer document
into a folder tmpdoc, then repack it to
out.odt, without the tmpdoc folder name.
sfk sel -sincedir proj1 proj2 +zipto out
if proj2 is a newer copy of proj1,
collect all files added or changed
since proj1 into out.zip
sfk zip out mydir +filter -!test
pack mydir to out.zip, but do not print
any names with "test" to terminal.