use bsdtar to generate zip file

2

i'm using GnuWin32's bsdtar, to extract it's simple:

bsdtar  xvf c:\test.zip -C  c:\temp\

but i failed to create zip files. I tried

bsdtar -cf test.zip a.csv b.csv

but the generated file couldn't be opened by winzip.

what's the correct way to generate zip file in command line?

athos

Posted 2017-08-02T10:57:41.190

Reputation: 1 954

Answers

2

From https://www.freebsd.org/cgi/man.cgi?query=bsdtar&sektion=1:

-a, --auto-compress
     (c mode only) Use the archive suffix to decide a set of the for-
     mat and the compressions.

So, you would have to use:

bsdtar -a -cf test.zip a.csv b.csv

Which, in fact, is exactly the example they give:

tar -a -cf archive.zip source.c source.h
     creates a new archive with zip format

Pro tip: everytime you are looking for how to do something with a command that comes from the *NIX world, try typing man <command> in Google. This technique never failed me.

Nathan.Eilisha Shiraini

Posted 2017-08-02T10:57:41.190

Reputation: 2 503

bsdtar: invalid option -- a Usage: List: bsdtar -tf <archive-filename> Extract: bsdtar -xf <archive-filename> Create: bsdtar -cf <archive-filename> [filenames...] Help: bsdtar --help – athos – 2017-08-02T11:15:49.817

Looks like only the oldest bsdtar don't have this option. According to the actual, up-to-date documentation, the -a option exists.

– Nathan.Eilisha Shiraini – 2017-08-02T11:23:33.827

However, there does not seem to be any other way to create a proper zip archive with bsdtar. If you are on Windows, you could try switching to 7z (the command line version of 7zip), but that would require you to change your commands (especially tedious if you have scripts using it). – Nathan.Eilisha Shiraini – 2017-08-02T11:31:13.573

After digging it seems that the GnuWin32 version of bsdtar is indeed seriously outdated. The GnuWin32 website itself states that it is still there "for archeological reasons". – Nathan.Eilisha Shiraini – 2017-08-02T11:41:02.890

thx I'll switch to 7zip – athos – 2017-08-02T12:23:41.740

You can try and update to the latest version of libarchive, although I do not know if they have a compiled bsdtar shipped with it. Sorry not to have any other solutions. – Nathan.Eilisha Shiraini – 2017-08-02T12:26:17.463