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
  • 2,249
  • 10
  • 40
  • 56

1 Answers1

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
  • 2,633
  • 1
  • 14
  • 24
  • bsdtar: invalid option -- a Usage: List: bsdtar -tf Extract: bsdtar -xf Create: bsdtar -cf [filenames...] Help: bsdtar --help – athos Aug 02 '17 at 11:15
  • Looks like only the oldest bsdtar don't have this option. According to the [actual, up-to-date documentation](https://github.com/libarchive/libarchive/wiki/ManPageBsdtar1#OPTIONS), the `-a` option exists. – Nathan.Eilisha Shiraini Aug 02 '17 at 11:23
  • 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 Aug 02 '17 at 11:31
  • 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 Aug 02 '17 at 11:41
  • thx I'll switch to 7zip – athos Aug 02 '17 at 12:23
  • 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 Aug 02 '17 at 12:26
  • Months later, a BSD TAR.exe was added to Windows 10 (1903) from build 17063 (December, 2017) – caoanan Jul 19 '21 at 03:07